PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / php / FunctionsPreg.php

FunctionsPreg.php in 404 Solution trunk, at includes/php/FunctionsPreg.php

68 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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