1 | <?php |
||
54 | class Route |
||
55 | { |
||
56 | /** |
||
57 | * |
||
58 | * The route failed to match at isCustomMatch(). |
||
59 | * |
||
60 | * @const string |
||
61 | * |
||
62 | */ |
||
63 | const FAILED_CUSTOM = 'FAILED_CUSTOM'; |
||
64 | |||
65 | /** |
||
66 | * |
||
67 | * Accepts these content types. |
||
68 | * |
||
69 | * @var array |
||
70 | * |
||
71 | */ |
||
72 | protected $accepts = []; |
||
73 | |||
74 | /** |
||
75 | * |
||
76 | * Allows these HTTP methods. |
||
77 | * |
||
78 | * @var array |
||
79 | * |
||
80 | */ |
||
81 | protected $allows = []; |
||
82 | |||
83 | /** |
||
84 | * |
||
85 | * Attribute values added by the rules. |
||
86 | * |
||
87 | * @var array |
||
88 | * |
||
89 | */ |
||
90 | protected $attributes = []; |
||
91 | |||
92 | /** |
||
93 | * |
||
94 | * Authentication/authorization values. |
||
95 | * |
||
96 | * @var mixed |
||
97 | * |
||
98 | */ |
||
99 | protected $auth; |
||
100 | |||
101 | /** |
||
102 | * |
||
103 | * Default attribute values. |
||
104 | * |
||
105 | * @var array |
||
106 | * |
||
107 | */ |
||
108 | protected $defaults = []; |
||
109 | |||
110 | /** |
||
111 | * |
||
112 | * Extra key-value pairs to attach to the route; intended for use by |
||
113 | * custom matching rules. |
||
114 | * |
||
115 | * @var array |
||
116 | * |
||
117 | */ |
||
118 | protected $extras = []; |
||
119 | |||
120 | /** |
||
121 | * |
||
122 | * The rule that failed, if any, during matching. |
||
123 | * |
||
124 | * @var string |
||
125 | * |
||
126 | */ |
||
127 | protected $failedRule; |
||
128 | |||
129 | /** |
||
130 | * |
||
131 | * The action, controller, callable, closure, etc. this route points to. |
||
132 | * |
||
133 | * @var mixed |
||
134 | * |
||
135 | */ |
||
136 | protected $handler; |
||
137 | |||
138 | /** |
||
139 | * |
||
140 | * The host string this route responds to. |
||
141 | * |
||
142 | * @var string |
||
143 | * |
||
144 | */ |
||
145 | protected $host; |
||
146 | |||
147 | /** |
||
148 | * |
||
149 | * The name for this route. |
||
150 | * |
||
151 | * @var string |
||
152 | * |
||
153 | */ |
||
154 | protected $name; |
||
155 | |||
156 | /** |
||
157 | * |
||
158 | * Prefix the route name with this string. |
||
159 | * |
||
160 | * @var string |
||
161 | * |
||
162 | */ |
||
163 | protected $namePrefix; |
||
164 | |||
165 | /** |
||
166 | * |
||
167 | * The path for this route. |
||
168 | * |
||
169 | * @var string |
||
170 | * |
||
171 | */ |
||
172 | protected $path; |
||
173 | |||
174 | /** |
||
175 | * |
||
176 | * Prefix the route path with this string. |
||
177 | * |
||
178 | * @var string |
||
179 | * |
||
180 | */ |
||
181 | protected $pathPrefix; |
||
182 | |||
183 | /** |
||
184 | * |
||
185 | * Should this route be used for matching? |
||
186 | * |
||
187 | * @var bool |
||
188 | * |
||
189 | */ |
||
190 | protected $isRoutable = true; |
||
191 | |||
192 | /** |
||
193 | * |
||
194 | * Should this route respond on a secure protocol? |
||
195 | * |
||
196 | * @var bool |
||
197 | * |
||
198 | */ |
||
199 | protected $secure = null; |
||
200 | |||
201 | /** |
||
202 | * |
||
203 | * Placeholder token names and regexes. |
||
204 | * |
||
205 | * @var array |
||
206 | * |
||
207 | */ |
||
208 | protected $tokens = []; |
||
209 | |||
210 | /** |
||
211 | * |
||
212 | * Wildcard token name, if any. |
||
213 | * |
||
214 | * @var string |
||
215 | * |
||
216 | */ |
||
217 | protected $wildcard = null; |
||
218 | |||
219 | /** |
||
220 | * |
||
221 | * Custom callable for isCustomMatch() logic. |
||
222 | * |
||
223 | * @var callable |
||
224 | * |
||
225 | */ |
||
226 | protected $is_match = null; |
||
227 | |||
228 | /** |
||
229 | * |
||
230 | * When cloning the Route, reset the `$attributes` to an empty array, and |
||
231 | * clear the `$failedRule`. |
||
232 | * |
||
233 | */ |
||
234 | 32 | public function __clone() |
|
240 | |||
241 | /** |
||
242 | * |
||
243 | * Magic read-only for all properties. |
||
244 | * |
||
245 | * @param string $key The property to read from. |
||
246 | * |
||
247 | * @return mixed |
||
248 | * |
||
249 | */ |
||
250 | 41 | public function __get($key) |
|
254 | |||
255 | /** |
||
256 | * |
||
257 | * Merges with the existing content types. |
||
258 | * |
||
259 | * @param string|array $accepts The content types. |
||
260 | * |
||
261 | * @return $this |
||
262 | * |
||
263 | */ |
||
264 | 1 | public function accepts($accepts) |
|
269 | |||
270 | /** |
||
271 | * |
||
272 | * Merges with the existing allowed methods. |
||
273 | * |
||
274 | * @param string|array $allows The allowed HTTP methods. |
||
275 | * |
||
276 | * @return $this |
||
277 | * |
||
278 | */ |
||
279 | 7 | public function allows($allows) |
|
284 | |||
285 | /** |
||
286 | * |
||
287 | * Merges with the existing attributes. |
||
288 | * |
||
289 | * @param array $attributes The attributes to add. |
||
290 | * |
||
291 | * @return $this |
||
292 | * |
||
293 | */ |
||
294 | 19 | public function attributes(array $attributes) |
|
299 | |||
300 | /** |
||
301 | * |
||
302 | * Sets the auth value. |
||
303 | * |
||
304 | * @param mixed $auth The auth value to set. |
||
305 | * |
||
306 | * @return $this |
||
307 | * |
||
308 | */ |
||
309 | 1 | public function auth($auth) |
|
314 | |||
315 | /** |
||
316 | * |
||
317 | * Merges with the existing default values for attributes. |
||
318 | * |
||
319 | * @param array $defaults Default values for attributes. |
||
320 | * |
||
321 | * @return $this |
||
322 | * |
||
323 | */ |
||
324 | 3 | public function defaults(array $defaults) |
|
329 | |||
330 | /** |
||
331 | * |
||
332 | * Merges with the existing extra key-value pairs; this merge is recursive, |
||
333 | * so the values can be arbitrarily deep. |
||
334 | * |
||
335 | * @param array $extras The extra key-value pairs. |
||
336 | * |
||
337 | * @return $this |
||
338 | * |
||
339 | */ |
||
340 | 3 | public function extras(array $extras) |
|
345 | |||
346 | /** |
||
347 | * |
||
348 | * Sets the failed rule. |
||
349 | * |
||
350 | * @param mixed $failedRule The failed rule. |
||
351 | * |
||
352 | * @return $this |
||
353 | * |
||
354 | */ |
||
355 | 6 | public function failedRule($failedRule) |
|
360 | |||
361 | /** |
||
362 | * |
||
363 | * The route leads to this handler. |
||
364 | * |
||
365 | * @param mixed $handler The handler for this route; if null, uses the |
||
366 | * route name. |
||
367 | * |
||
368 | * @return $this |
||
369 | * |
||
370 | */ |
||
371 | 23 | public function handler($handler) |
|
379 | |||
380 | /** |
||
381 | * |
||
382 | * Sets the host. |
||
383 | * |
||
384 | * @param mixed $host The host. |
||
385 | * |
||
386 | * @return $this |
||
387 | * |
||
388 | */ |
||
389 | 5 | public function host($host) |
|
394 | |||
395 | /** |
||
396 | * |
||
397 | * Sets whether or not this route should be used for matching. |
||
398 | * |
||
399 | * @param bool $isRoutable If true, this route can be matched; if not, it |
||
400 | * can be used only to generate a path. |
||
401 | * |
||
402 | * @return $this |
||
403 | * |
||
404 | */ |
||
405 | 4 | public function isRoutable($isRoutable = true) |
|
410 | |||
411 | /** |
||
412 | * |
||
413 | * Sets the route name; immutable once set. |
||
414 | * |
||
415 | * @param string $name The route name. |
||
416 | * |
||
417 | * @return $this |
||
418 | * |
||
419 | * @throws Exception\ImmutableProperty when the name has already been set. |
||
420 | * |
||
421 | */ |
||
422 | 25 | public function name($name) |
|
431 | |||
432 | /** |
||
433 | * |
||
434 | * Appends to the existing name prefix; immutable once $name is set. |
||
435 | * |
||
436 | * @param string $namePrefix The name prefix to append. |
||
437 | * |
||
438 | * @return $this |
||
439 | * |
||
440 | * @throws Exception\ImmutableProperty when the name has already been set. |
||
441 | * |
||
442 | */ |
||
443 | 5 | public function namePrefix($namePrefix) |
|
452 | |||
453 | /** |
||
454 | * |
||
455 | * Sets the route path; immutable once set. |
||
456 | * |
||
457 | * @param string $path The route path. |
||
458 | * |
||
459 | * @return $this |
||
460 | * |
||
461 | * @throws Exception\ImmutableProperty when the name has already been set. |
||
462 | * |
||
463 | */ |
||
464 | 42 | public function path($path) |
|
473 | |||
474 | /** |
||
475 | * |
||
476 | * Appends to the existing path prefix; immutable once $path is set. |
||
477 | * |
||
478 | * @param string $pathPrefix The path prefix to append. |
||
479 | * |
||
480 | * @return $this |
||
481 | * |
||
482 | * @throws Exception\ImmutableProperty when the path has already been set. |
||
483 | * |
||
484 | */ |
||
485 | 5 | public function pathPrefix($pathPrefix) |
|
494 | |||
495 | /** |
||
496 | * |
||
497 | * Sets whether or not the route must be secure. |
||
498 | * |
||
499 | * @param bool|null $secure If true, the server must indicate an HTTPS request; |
||
500 | * if false, it must *not* be HTTPS; if null, it doesn't matter. |
||
501 | * |
||
502 | * @return $this |
||
503 | * |
||
504 | */ |
||
505 | 5 | public function secure($secure = true) |
|
510 | |||
511 | /** |
||
512 | * |
||
513 | * Merges with the existing tokens. |
||
514 | * |
||
515 | * @param array $tokens The tokens. |
||
516 | * |
||
517 | * @return $this |
||
518 | * |
||
519 | */ |
||
520 | 10 | public function tokens(array $tokens) |
|
525 | |||
526 | /** |
||
527 | * |
||
528 | * Sets the name of the wildcard token, if any. |
||
529 | * |
||
530 | * @param string $wildcard The name of the wildcard token, if any. |
||
531 | * |
||
532 | * @return $this |
||
533 | * |
||
534 | */ |
||
535 | 3 | public function wildcard($wildcard) |
|
540 | |||
541 | /** |
||
542 | * |
||
543 | * Sets a custom callable to evaluate the route for matching. |
||
544 | * |
||
545 | * @param callable $is_match A custom callable to evaluate the route. |
||
546 | * |
||
547 | * @return $this |
||
548 | * |
||
549 | */ |
||
550 | 2 | public function setIsMatchCallable($is_match) |
|
555 | |||
556 | /** |
||
557 | * |
||
558 | * Checks that the custom Route `$is_match` callable returns true, given |
||
559 | * the server values. |
||
560 | * |
||
561 | * @param ServerRequestInterface $request The incoming request. |
||
562 | * |
||
563 | * @return bool True on a match, false if not. |
||
564 | * |
||
565 | */ |
||
566 | 5 | public function isCustomMatch(ServerRequestInterface $request) |
|
583 | } |
||
584 |