1 | <?php |
||
13 | final class TextMatcher extends Matcher |
||
14 | { |
||
15 | const PATTERN_REGEXP = "/@[a-zA-Z\\.]+@(\\.[a-zA-Z0-9_]+\\([a-zA-Z0-9{},:@\\.\"'\\(\\)]*\\))*/"; |
||
16 | |||
17 | const PATTERN_REGEXP_PLACEHOLDER_TEMPLATE = "__PLACEHOLDER%d__"; |
||
18 | |||
19 | /** |
||
20 | * @var Parser |
||
21 | */ |
||
22 | private $parser; |
||
23 | |||
24 | /** |
||
25 | * @var ValueMatcher |
||
26 | */ |
||
27 | private $matcher; |
||
28 | |||
29 | /** |
||
30 | * @param ValueMatcher $matcher |
||
31 | * @param Parser $parser |
||
32 | */ |
||
33 | public function __construct(ValueMatcher $matcher, Parser $parser) |
||
38 | |||
39 | /** |
||
40 | * {@inheritDoc} |
||
41 | */ |
||
42 | public function match($value, $pattern) |
||
80 | |||
81 | /** |
||
82 | * {@inheritDoc} |
||
83 | */ |
||
84 | public function canMatch($pattern) |
||
100 | |||
101 | /** |
||
102 | * Reaplce each type pattern (@[email protected]("lorem")) with placeholder, in order |
||
103 | * to use preg_quote without destroying pattern & expanders. |
||
104 | * |
||
105 | * before replacement: "/users/@[email protected](200)/active" |
||
106 | * after replacement: "/users/__PLACEHOLDER0__/active" |
||
107 | * |
||
108 | * @param string $patternRegex |
||
109 | * @return TypePattern[]|array |
||
110 | */ |
||
111 | private function replaceTypePatternsWithPlaceholders(&$patternRegex) |
||
128 | |||
129 | |||
130 | /** |
||
131 | * Replace placeholders with type pattern regular expressions |
||
132 | * before replacement: "/users/__PLACEHOLDER0__/active" |
||
133 | * after replacement: "/^\/users\/(\-?[0-9]*)\/active$/" |
||
134 | * |
||
135 | * @param $patternRegex |
||
136 | * @return string |
||
137 | * @throws \Coduo\PHPMatcher\Exception\UnknownTypeException |
||
138 | */ |
||
139 | private function replacePlaceholderWithPatternRegexes($patternRegex, array $patternsReplacedWithRegex) |
||
152 | |||
153 | /** |
||
154 | * Prepare regular expression |
||
155 | * |
||
156 | * @param string $patternRegex |
||
157 | * @return string |
||
158 | */ |
||
159 | private function prepareRegex($patternRegex) |
||
163 | } |
||
164 |