| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Backward-compatibility shim. New code should depend on |
| 10 |
* ABJ_404_Solution_RegexHelperPreg directly (the preg helper is useful |
| 11 |
* even when mbstring is loaded - callers wanting PCRE regex semantics |
| 12 |
* regardless of host extension reach for it explicitly). |
| 13 |
* |
| 14 |
* Wires Functions to the Preg variants of MbStringAdapter and RegexHelper |
| 15 |
* so the polymorphic primitives use native string / preg_* fallbacks. The |
| 16 |
* class itself has no extra behavior beyond adapter selection. |
| 17 |
*/ |
| 18 |
class ABJ_404_Solution_FunctionsPreg extends ABJ_404_Solution_Functions { |
| 19 |
|
| 20 |
/** @var self|null */ |
| 21 |
private static $instance = null; |
| 22 |
/** |
| 23 |
* Test seam: install or clear the cached singleton instance without |
| 24 |
* private-field reflection. Pass null to reset between tests; pass a |
| 25 |
* configured instance (or double) to install it (M105 singleton-reset seam). |
| 26 |
* |
| 27 |
* @param self|null $instance |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public static function setInstance($instance) { |
| 31 |
self::$instance = $instance; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
/** |
| 36 |
* @param ABJ_404_Solution_Logging|null $logging |
| 37 |
* @param ABJ_404_Solution_RequestContext|null $requestContext |
| 38 |
*/ |
| 39 |
public function __construct($logging = null, $requestContext = null) { |
| 40 |
parent::__construct( |
| 41 |
$logging, |
| 42 |
$requestContext, |
| 43 |
ABJ_404_Solution_MbStringAdapterPreg::getInstance(), |
| 44 |
ABJ_404_Solution_RegexHelperPreg::getInstance() |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
public static function getInstance(): self { |
| 49 |
if (self::$instance === null) { |
| 50 |
self::$instance = new self(); |
| 51 |
} |
| 52 |
return self::$instance; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Find a delimiter character that does not occur in $pattern. Exposed |
| 57 |
* here for the rare caller that constructed a delimiter-aware PCRE |
| 58 |
* string manually; new code should call |
| 59 |
* ABJ_404_Solution_RegexHelperPreg::findADelimiter() directly. |
| 60 |
* |
| 61 |
* @param string $pattern |
| 62 |
* @return string |
| 63 |
*/ |
| 64 |
public function findADelimiter(string $pattern): string { |
| 65 |
return ABJ_404_Solution_RegexHelperPreg::getInstance()->findADelimiter($pattern); |
| 66 |
} |
| 67 |
} |
| 68 |
|