1 | <?php |
||
20 | class RegexFactory |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Contains the expression being built |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $expression; |
||
29 | |||
30 | /** |
||
31 | * Keeps track of any open delimiters to ensure everything is closed correctly |
||
32 | * |
||
33 | * @var int |
||
34 | */ |
||
35 | protected $openDelimiters; |
||
36 | |||
37 | /** |
||
38 | * Contains the status of any flags that have been added |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $flags; |
||
43 | |||
44 | public function __construct() |
||
48 | |||
49 | /** |
||
50 | * Resets the string being built |
||
51 | * |
||
52 | * @return $this |
||
53 | * |
||
54 | * @since 2.0 |
||
55 | */ |
||
56 | public function reset() |
||
64 | |||
65 | /** |
||
66 | * Gets the built expression |
||
67 | * |
||
68 | * @param bool $delimit Set to false to disable adding the delimiters to the string |
||
69 | * |
||
70 | * @return string |
||
71 | * |
||
72 | * @since 2.0 |
||
73 | */ |
||
74 | public function get($delimit = true) |
||
91 | |||
92 | /** |
||
93 | * Calls get() to return the built regex |
||
94 | * |
||
95 | * @return string |
||
96 | * |
||
97 | * @since 2.0 |
||
98 | */ |
||
99 | public function __toString() |
||
103 | |||
104 | /** |
||
105 | * Adds any given value to the expression being built |
||
106 | * |
||
107 | * @param string $value |
||
108 | * |
||
109 | * @return $this |
||
110 | * |
||
111 | * @since 2.0 |
||
112 | */ |
||
113 | public function value($value) |
||
119 | |||
120 | /** |
||
121 | * Starts a group capture |
||
122 | * |
||
123 | * @return $this |
||
124 | * |
||
125 | * @since 2.0 |
||
126 | */ |
||
127 | public function startGroupCapture() |
||
134 | |||
135 | /** |
||
136 | * Ends a group capture |
||
137 | * |
||
138 | * @return $this |
||
139 | * |
||
140 | * @since 2.0 |
||
141 | */ |
||
142 | public function endGroupCapture() |
||
149 | |||
150 | /** |
||
151 | * Starts a range indicator |
||
152 | * |
||
153 | * @return $this |
||
154 | * |
||
155 | * @since 2.0 |
||
156 | */ |
||
157 | public function startRange() |
||
164 | |||
165 | /** |
||
166 | * Ends a range indicator |
||
167 | * |
||
168 | * @return $this |
||
169 | * |
||
170 | * @since 2.0 |
||
171 | */ |
||
172 | public function endRange() |
||
179 | |||
180 | /** |
||
181 | * Adds a a-z range |
||
182 | * |
||
183 | * @return $this |
||
184 | * |
||
185 | * @since 2.0 |
||
186 | */ |
||
187 | public function lowercase() |
||
193 | |||
194 | /** |
||
195 | * Adds a A-Z range |
||
196 | * |
||
197 | * @return $this |
||
198 | * |
||
199 | * @since 2.0 |
||
200 | */ |
||
201 | public function uppercase() |
||
207 | |||
208 | /** |
||
209 | * Adds a 0-9 range |
||
210 | * |
||
211 | * @return $this |
||
212 | * |
||
213 | * @since 2.0 |
||
214 | */ |
||
215 | public function numeric() |
||
221 | |||
222 | /** |
||
223 | * Adds an "any" matcher |
||
224 | * |
||
225 | * @return $this |
||
226 | * |
||
227 | * @since 2.0 |
||
228 | */ |
||
229 | public function any() |
||
235 | |||
236 | /** |
||
237 | * Matches against the start of the string |
||
238 | * |
||
239 | * @return $this |
||
240 | * |
||
241 | * @since 2.0 |
||
242 | */ |
||
243 | public function start() |
||
249 | |||
250 | /** |
||
251 | * Matches the end of the string |
||
252 | * |
||
253 | * @return $this |
||
254 | * |
||
255 | * @since 2.0 |
||
256 | */ |
||
257 | public function end() |
||
263 | |||
264 | /** |
||
265 | * Matches none of one of the preceding statements |
||
266 | * |
||
267 | * @return $this |
||
268 | * |
||
269 | * @since 2.0 |
||
270 | */ |
||
271 | public function noneOrOne() |
||
277 | |||
278 | /** |
||
279 | * Matches none or more of the preceding statement |
||
280 | * |
||
281 | * @return $this |
||
282 | * |
||
283 | * @since 2.0 |
||
284 | */ |
||
285 | public function noneOrMany() |
||
291 | |||
292 | /** |
||
293 | * Matches one or more of the preceding statement |
||
294 | * |
||
295 | * @return $this |
||
296 | * |
||
297 | * @since 2.0 |
||
298 | */ |
||
299 | public function oneOrMore() |
||
305 | |||
306 | /** |
||
307 | * Adds an or "|" |
||
308 | * |
||
309 | * @return $this |
||
310 | * |
||
311 | * @since 2.0 |
||
312 | */ |
||
313 | public function addOr() |
||
319 | |||
320 | /** |
||
321 | * Adds a {} to match a quantity |
||
322 | * |
||
323 | * @param int $min |
||
324 | * @param int|null $max |
||
325 | * |
||
326 | * @return $this |
||
327 | * |
||
328 | * @since 2.0 |
||
329 | */ |
||
330 | public function matchQuantity($min, $max = null) |
||
345 | |||
346 | /** |
||
347 | * Makes the regex case insensitive by adding the i flag |
||
348 | * |
||
349 | * @return $this |
||
350 | * |
||
351 | * @since 2.0 |
||
352 | */ |
||
353 | public function caseInsensitive() |
||
359 | |||
360 | /** |
||
361 | * Ignores whitespace in the regex by adding the x flag |
||
362 | * |
||
363 | * @return $this |
||
364 | * |
||
365 | * @since 2.0 |
||
366 | */ |
||
367 | public function ignoreWhitespace() |
||
373 | |||
374 | /** |
||
375 | * Makes #{} substitutions happen only once by adding the o flag |
||
376 | * |
||
377 | * @return $this |
||
378 | * |
||
379 | * @since 2.0 |
||
380 | */ |
||
381 | public function singleSubstitution() |
||
387 | |||
388 | /** |
||
389 | * Makes dot match newline characters using the m flag |
||
390 | * |
||
391 | * @return $this |
||
392 | * |
||
393 | * @since 2.0 |
||
394 | */ |
||
395 | public function dotNewline() |
||
401 | |||
402 | } |
||
403 |