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 / core / RegexHelperMb.php

RegexHelperMb.php in 404 Solution trunk, at includes/core/RegexHelperMb.php

62 lines 1.8 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 * mbstring-backed implementation of ABJ_404_Solution_RegexHelper.
10 *
11 * Use when the PHP mbstring extension is loaded. The regex methods wrap
12 * mb_ereg / mb_eregi / mb_ereg_replace, which use POSIX regex syntax (no
13 * delimiters, no PCRE shorthand like \d). Callers wanting PCRE syntax must
14 * use RegexHelperPreg directly.
15 */
16 class ABJ_404_Solution_RegexHelperMb extends ABJ_404_Solution_RegexHelper {
17
18 /** @var self|null */
19 private static $instance = null;
20 /**
21 * Test seam: install or clear the cached singleton instance without
22 * private-field reflection. Pass null to reset between tests; pass a
23 * configured instance (or double) to install it (M105 singleton-reset seam).
24 *
25 * @param self|null $instance
26 * @return void
27 */
28 public static function setInstance($instance) {
29 self::$instance = $instance;
30 }
31
32
33 public static function getInstance(): self {
34 if (self::$instance === null) {
35 self::$instance = new self();
36 }
37 return self::$instance;
38 }
39
40 /**
41 * @param array<int, string>|null $regs
42 * @return bool|int
43 */
44 public function regexMatch(string $pattern, string $string, ?array &$regs = null) {
45 return mb_ereg($pattern, $string, $regs);
46 }
47
48 /**
49 * @param array<int, string>|null $regs
50 * @return bool|int
51 */
52 public function regexMatchi(string $pattern, string $string, ?array &$regs = null) {
53 return mb_eregi($pattern, $string, $regs);
54 }
55
56 /** @return string|null */
57 public function regexReplace($pattern, $replacement, $string) {
58 $result = mb_ereg_replace($pattern, $replacement, $string);
59 return is_string($result) ? $result : $string;
60 }
61 }
62