1 | <?php |
||
54 | class Route |
||
55 | { |
||
56 | /** |
||
57 | * |
||
58 | * Accepts these content types. |
||
59 | * |
||
60 | * @var array |
||
61 | * |
||
62 | */ |
||
63 | protected $accepts = []; |
||
64 | |||
65 | /** |
||
66 | * |
||
67 | * Allows these HTTP methods. |
||
68 | * |
||
69 | * @var array |
||
70 | * |
||
71 | */ |
||
72 | protected $allows = []; |
||
73 | |||
74 | /** |
||
75 | * |
||
76 | * Attribute values added by the rules. |
||
77 | * |
||
78 | * @var array |
||
79 | * |
||
80 | */ |
||
81 | protected $attributes = []; |
||
82 | |||
83 | /** |
||
84 | * |
||
85 | * Authentication/authorization values. |
||
86 | * |
||
87 | * @var mixed |
||
88 | * |
||
89 | */ |
||
90 | protected $auth; |
||
91 | |||
92 | /** |
||
93 | * |
||
94 | * Default attribute values. |
||
95 | * |
||
96 | * @var array |
||
97 | * |
||
98 | */ |
||
99 | protected $defaults = []; |
||
100 | |||
101 | /** |
||
102 | * |
||
103 | * Extra key-value pairs to attach to the route; intended for use by |
||
104 | * custom matching rules. |
||
105 | * |
||
106 | * @var array |
||
107 | * |
||
108 | */ |
||
109 | protected $extras = []; |
||
110 | |||
111 | /** |
||
112 | * |
||
113 | * The rule that failed, if any, during matching. |
||
114 | * |
||
115 | * @var string |
||
116 | * |
||
117 | */ |
||
118 | protected $failedRule; |
||
119 | |||
120 | /** |
||
121 | * |
||
122 | * The action, controller, callable, closure, etc. this route points to. |
||
123 | * |
||
124 | * @var mixed |
||
125 | * |
||
126 | */ |
||
127 | protected $handler; |
||
128 | |||
129 | /** |
||
130 | * |
||
131 | * The host string this route responds to. |
||
132 | * |
||
133 | * @var string |
||
134 | * |
||
135 | */ |
||
136 | protected $host; |
||
137 | |||
138 | /** |
||
139 | * |
||
140 | * The name for this route. |
||
141 | * |
||
142 | * @var string |
||
143 | * |
||
144 | */ |
||
145 | protected $name; |
||
146 | |||
147 | /** |
||
148 | * |
||
149 | * Prefix the route name with this string. |
||
150 | * |
||
151 | * @var string |
||
152 | * |
||
153 | */ |
||
154 | protected $namePrefix; |
||
155 | |||
156 | /** |
||
157 | * |
||
158 | * The path for this route. |
||
159 | * |
||
160 | * @var string |
||
161 | * |
||
162 | */ |
||
163 | protected $path; |
||
164 | |||
165 | /** |
||
166 | * |
||
167 | * Prefix the route path with this string. |
||
168 | * |
||
169 | * @var string |
||
170 | * |
||
171 | */ |
||
172 | protected $pathPrefix; |
||
173 | |||
174 | /** |
||
175 | * |
||
176 | * Should this route be used for matching? |
||
177 | * |
||
178 | * @var bool |
||
179 | * |
||
180 | */ |
||
181 | protected $isRoutable = true; |
||
182 | |||
183 | /** |
||
184 | * |
||
185 | * Should this route respond on a secure protocol? |
||
186 | * |
||
187 | * @var bool |
||
188 | * |
||
189 | */ |
||
190 | protected $secure = null; |
||
191 | |||
192 | /** |
||
193 | * |
||
194 | * A callable to use for special matching logic on this individual Route. |
||
195 | * |
||
196 | * @var callable |
||
197 | * |
||
198 | */ |
||
199 | protected $special; |
||
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 | * When cloning the Route, reset the `$attributes` to an empty array, and |
||
222 | * clear the `$failedRule`. |
||
223 | * |
||
224 | */ |
||
225 | 33 | public function __clone() |
|
231 | |||
232 | /** |
||
233 | * |
||
234 | * Magic read-only for all properties. |
||
235 | * |
||
236 | * @param string $key The property to read from. |
||
237 | * |
||
238 | * @return mixed |
||
239 | * |
||
240 | */ |
||
241 | 44 | public function __get($key) |
|
245 | |||
246 | /** |
||
247 | * |
||
248 | * Merges with the existing content types. |
||
249 | * |
||
250 | * @param string|array $accepts The content types. |
||
251 | * |
||
252 | * @return $this |
||
253 | * |
||
254 | */ |
||
255 | 1 | public function accepts($accepts) |
|
260 | |||
261 | /** |
||
262 | * |
||
263 | * Merges with the existing allowed methods. |
||
264 | * |
||
265 | * @param string|array $allows The allowed HTTP methods. |
||
266 | * |
||
267 | * @return $this |
||
268 | * |
||
269 | */ |
||
270 | 5 | public function allows($allows) |
|
275 | |||
276 | /** |
||
277 | * |
||
278 | * Merges with the existing attributes. |
||
279 | * |
||
280 | * @param array $attributes The attributes to add. |
||
281 | * |
||
282 | * @return $this |
||
283 | * |
||
284 | */ |
||
285 | 18 | public function attributes(array $attributes) |
|
290 | |||
291 | /** |
||
292 | * |
||
293 | * Sets the auth value. |
||
294 | * |
||
295 | * @param mixed $auth The auth value to set. |
||
296 | * |
||
297 | * @return $this |
||
298 | * |
||
299 | */ |
||
300 | 1 | public function auth($auth) |
|
305 | |||
306 | /** |
||
307 | * |
||
308 | * Merges with the existing default values for attributes. |
||
309 | * |
||
310 | * @param array $defaults Default values for attributes. |
||
311 | * |
||
312 | * @return $this |
||
313 | * |
||
314 | */ |
||
315 | 3 | public function defaults(array $defaults) |
|
320 | |||
321 | /** |
||
322 | * |
||
323 | * Merges with the existing extra key-value pairs; this merge is recursive, |
||
324 | * so the values can be arbitrarily deep. |
||
325 | * |
||
326 | * @param array $extras The extra key-value pairs. |
||
327 | * |
||
328 | * @return $this |
||
329 | * |
||
330 | */ |
||
331 | 1 | public function extras(array $extras) |
|
336 | |||
337 | /** |
||
338 | * |
||
339 | * Sets the failed rule. |
||
340 | * |
||
341 | * @param mixed $failedRule The failed rule. |
||
342 | * |
||
343 | * @return $this |
||
344 | * |
||
345 | */ |
||
346 | 4 | public function failedRule($failedRule) |
|
351 | |||
352 | /** |
||
353 | * |
||
354 | * The route leads to this handler. |
||
355 | * |
||
356 | * @param mixed $handler The handler for this route; if null, uses the |
||
357 | * route name. |
||
358 | * |
||
359 | * @return $this |
||
360 | * |
||
361 | */ |
||
362 | 23 | public function handler($handler) |
|
370 | |||
371 | /** |
||
372 | * |
||
373 | * Sets the host. |
||
374 | * |
||
375 | * @param mixed $host The host. |
||
376 | * |
||
377 | * @return $this |
||
378 | * |
||
379 | */ |
||
380 | 5 | public function host($host) |
|
385 | |||
386 | /** |
||
387 | * |
||
388 | * Sets whether or not this route should be used for matching. |
||
389 | * |
||
390 | * @param bool $isRoutable If true, this route can be matched; if not, it |
||
391 | * can be used only to generate a path. |
||
392 | * |
||
393 | * @return $this |
||
394 | * |
||
395 | */ |
||
396 | 4 | public function isRoutable($isRoutable = true) |
|
401 | |||
402 | /** |
||
403 | * |
||
404 | * Sets the route name; immutable once set. |
||
405 | * |
||
406 | * @param string $name The route name. |
||
407 | * |
||
408 | * @return $this |
||
409 | * |
||
410 | * @throws Exception\ImmutableProperty when the name has already been set. |
||
411 | * |
||
412 | */ |
||
413 | 25 | public function name($name) |
|
422 | |||
423 | /** |
||
424 | * |
||
425 | * Appends to the existing name prefix; immutable once $name is set. |
||
426 | * |
||
427 | * @param string $namePrefix The name prefix to append. |
||
428 | * |
||
429 | * @return $this |
||
430 | * |
||
431 | * @throws Exception\ImmutableProperty when the name has already been set. |
||
432 | * |
||
433 | */ |
||
434 | 5 | public function namePrefix($namePrefix) |
|
443 | |||
444 | /** |
||
445 | * |
||
446 | * Sets the route path; immutable once set. |
||
447 | * |
||
448 | * @param string $path The route path. |
||
449 | * |
||
450 | * @return $this |
||
451 | * |
||
452 | * @throws Exception\ImmutableProperty when the name has already been set. |
||
453 | * |
||
454 | */ |
||
455 | 44 | public function path($path) |
|
464 | |||
465 | /** |
||
466 | * |
||
467 | * Appends to the existing path prefix; immutable once $path is set. |
||
468 | * |
||
469 | * @param string $pathPrefix The path prefix to append. |
||
470 | * |
||
471 | * @return $this |
||
472 | * |
||
473 | * @throws Exception\ImmutableProperty when the path has already been set. |
||
474 | * |
||
475 | */ |
||
476 | 5 | public function pathPrefix($pathPrefix) |
|
485 | |||
486 | /** |
||
487 | * |
||
488 | * Sets whether or not the route must be secure. |
||
489 | * |
||
490 | * @param bool|null $secure If true, the server must indicate an HTTPS request; |
||
491 | * if false, it must *not* be HTTPS; if null, it doesn't matter. |
||
492 | * |
||
493 | * @return $this |
||
494 | * |
||
495 | */ |
||
496 | 5 | public function secure($secure = true) |
|
501 | |||
502 | /** |
||
503 | * |
||
504 | * A callable to use for special matching logic on this individual Route. |
||
505 | * |
||
506 | * @param callable|null $special A callable to invoke for special matching |
||
507 | * logic on this individiual route. The callable should have the signature |
||
508 | * `function ($request, $route) : bool`. (Use null or another empty value |
||
509 | * to indicate there is no special matching logic.) |
||
510 | * |
||
511 | * @return $this |
||
512 | * |
||
513 | */ |
||
514 | 2 | public function special($special) |
|
519 | |||
520 | /** |
||
521 | * |
||
522 | * Merges with the existing tokens. |
||
523 | * |
||
524 | * @param array $tokens The tokens. |
||
525 | * |
||
526 | * @return $this |
||
527 | * |
||
528 | */ |
||
529 | 13 | public function tokens(array $tokens) |
|
534 | |||
535 | /** |
||
536 | * |
||
537 | * Sets the name of the wildcard token, if any. |
||
538 | * |
||
539 | * @param string $wildcard The name of the wildcard token, if any. |
||
540 | * |
||
541 | * @return $this |
||
542 | * |
||
543 | */ |
||
544 | 3 | public function wildcard($wildcard) |
|
549 | } |
||
550 |