1 | <?php |
||
47 | class Route |
||
48 | { |
||
49 | /** |
||
50 | * Route name |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $name; |
||
55 | /** |
||
56 | * Route path |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $path; |
||
61 | /** |
||
62 | * Route action |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $action; |
||
67 | /** |
||
68 | * Route tokens |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $tokens = []; |
||
73 | /** |
||
74 | * Route default values |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $defaults = []; |
||
79 | /** |
||
80 | * Route wildcard name |
||
81 | * |
||
82 | * @var string|null |
||
83 | */ |
||
84 | protected $wildcard = null; |
||
85 | /** |
||
86 | * Route host |
||
87 | * |
||
88 | * @var string|null |
||
89 | */ |
||
90 | protected $host = null; |
||
91 | /** |
||
92 | * Allowed accept headers |
||
93 | * |
||
94 | * @var array |
||
95 | */ |
||
96 | protected $accepts = []; |
||
97 | /** |
||
98 | * Allowed HTTP verbs |
||
99 | * |
||
100 | * @var array |
||
101 | */ |
||
102 | protected $verbs = []; |
||
103 | /** |
||
104 | * Secure protocol behaviour |
||
105 | * |
||
106 | * @var boolean|null |
||
107 | */ |
||
108 | protected $secure = false; |
||
109 | /** |
||
110 | * Authentication parameters |
||
111 | * |
||
112 | * @var mixed |
||
113 | */ |
||
114 | protected $auth = null; |
||
115 | /** |
||
116 | * Custom extra parameters |
||
117 | * |
||
118 | * @var mixed |
||
119 | */ |
||
120 | protected $extras = null; |
||
121 | /** |
||
122 | * Allowed HTTP verbs |
||
123 | * |
||
124 | * @var array |
||
125 | */ |
||
126 | protected static $validVerbs = [ |
||
127 | self::GET => true, |
||
128 | self::POST => true, |
||
129 | self::PATCH => true, |
||
130 | self::DELETE => true, |
||
131 | self::OPTIONS => true, |
||
132 | self::HEAD => true |
||
133 | ]; |
||
134 | /** |
||
135 | * GET request |
||
136 | * |
||
137 | * @var string |
||
138 | */ |
||
139 | const GET = 'get'; |
||
140 | /** |
||
141 | * POST request |
||
142 | * |
||
143 | * @var string |
||
144 | */ |
||
145 | const POST = 'post'; |
||
146 | /** |
||
147 | * PATCH request |
||
148 | * |
||
149 | * @var string |
||
150 | */ |
||
151 | const PATCH = 'patch'; |
||
152 | /** |
||
153 | * DELETE request |
||
154 | * |
||
155 | * @var string |
||
156 | */ |
||
157 | const DELETE = 'delete'; |
||
158 | /** |
||
159 | * OPTIONS request |
||
160 | * |
||
161 | * @var string |
||
162 | */ |
||
163 | const OPTIONS = 'options'; |
||
164 | /** |
||
165 | * HEAD request |
||
166 | * |
||
167 | * @var string |
||
168 | */ |
||
169 | const HEAD = 'head'; |
||
170 | |||
171 | /** |
||
172 | * Route constructor |
||
173 | * |
||
174 | * @param string|array $verbs Allowed HTTP verbs |
||
175 | * @param string $name Route name |
||
176 | * @param string $path Route path |
||
177 | * @param string $action Route action |
||
178 | */ |
||
179 | public function __construct($verbs, $name, $path, $action) |
||
193 | |||
194 | /** |
||
195 | * Get the route name |
||
196 | * |
||
197 | * @return string Route name |
||
198 | */ |
||
199 | public function getName() |
||
203 | |||
204 | /** |
||
205 | * Get the route path |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | public function getPath() |
||
213 | |||
214 | public function getAction() |
||
218 | |||
219 | /** |
||
220 | * Get the route tokens |
||
221 | * |
||
222 | * @return array Route tokens |
||
223 | */ |
||
224 | public function getTokens() |
||
228 | |||
229 | /** |
||
230 | * Set the route tokens |
||
231 | * |
||
232 | * @param array $tokens Route tokens |
||
233 | * @return Route Self reference |
||
234 | */ |
||
235 | public function setTokens(array $tokens) |
||
240 | |||
241 | /** |
||
242 | * Get the route defaults |
||
243 | * |
||
244 | * @return array Route defaults |
||
245 | */ |
||
246 | public function getDefaults() |
||
250 | |||
251 | /** |
||
252 | * Set the route defaults |
||
253 | * |
||
254 | * @param array $defaults Route defaults |
||
255 | * @return Route Self reference |
||
256 | */ |
||
257 | public function setDefaults(array $defaults) |
||
262 | |||
263 | /** |
||
264 | * Set the route wildcard name |
||
265 | * |
||
266 | * @return null|string |
||
267 | */ |
||
268 | public function getWildcard() |
||
272 | |||
273 | /** |
||
274 | * Get the route wildcard name |
||
275 | * |
||
276 | * @param null|string $wildcard Wildcard name |
||
277 | * @return Route Self reference |
||
278 | */ |
||
279 | public function setWildcard($wildcard) |
||
284 | |||
285 | /** |
||
286 | * Get the route host |
||
287 | * |
||
288 | * @return null|string Route host |
||
289 | */ |
||
290 | public function getHost() |
||
294 | |||
295 | /** |
||
296 | * Set the route host |
||
297 | * |
||
298 | * @param null|string $host Route host |
||
299 | * @return Route Self reference |
||
300 | */ |
||
301 | public function setHost($host) |
||
306 | |||
307 | /** |
||
308 | * Get the allowed Accept headers |
||
309 | * |
||
310 | * @return array Allowed Accept headers |
||
311 | */ |
||
312 | public function getAccepts() |
||
316 | |||
317 | /** |
||
318 | * Set the allowed Accept headers |
||
319 | * |
||
320 | * @param array $accepts Allowed Accept headers |
||
321 | * @return Route Self reference |
||
322 | */ |
||
323 | public function setAccepts(array $accepts) |
||
328 | |||
329 | /** |
||
330 | * Get the allowed HTTP verbs |
||
331 | * |
||
332 | * @return array Allowed HTTP verbs |
||
333 | */ |
||
334 | public function getVerbs() |
||
338 | |||
339 | /** |
||
340 | * Set the allowed HTTP verbs |
||
341 | * |
||
342 | * @param array $verbs Allowed HTTP verbs |
||
343 | * @return Route Self reference |
||
344 | */ |
||
345 | public function setVerbs(array $verbs) |
||
350 | |||
351 | /** |
||
352 | * Get the secure protocol mode |
||
353 | * |
||
354 | * @return boolean|null Secure protocol mode |
||
355 | */ |
||
356 | public function getSecure() |
||
360 | |||
361 | /** |
||
362 | * Set the secure protocol mode |
||
363 | * |
||
364 | * @param boolean|null $secure Secure protocol mode |
||
365 | * @return Route Self reference |
||
366 | */ |
||
367 | public function setSecure($secure) |
||
372 | |||
373 | /** |
||
374 | * Get the authentication information |
||
375 | * |
||
376 | * @return mixed Authentication information |
||
377 | */ |
||
378 | public function getAuth() |
||
382 | |||
383 | /** |
||
384 | * Set the authentication information |
||
385 | * |
||
386 | * @param mixed $auth Authentication information |
||
387 | * @return Route Self reference |
||
388 | */ |
||
389 | public function setAuth($auth) |
||
394 | |||
395 | /** |
||
396 | * Get the custom extra information |
||
397 | * |
||
398 | * @return mixed Custom extra information |
||
399 | */ |
||
400 | public function getExtras() |
||
404 | |||
405 | /** |
||
406 | * Set the custom extra information |
||
407 | * |
||
408 | * @param mixed $extras Custom extra information |
||
409 | * @return Route Self reference |
||
410 | */ |
||
411 | public function setExtras($extras) |
||
416 | |||
417 | /** |
||
418 | * Validate the allowed HTTP verbs |
||
419 | * |
||
420 | * @param string|array $verbs Allowed HTTP verbs |
||
421 | * @throws InvalidArgumentException If the HTTP verb list is empty |
||
422 | * @throws InvalidArgumentException If the HTTP verb is invalid |
||
423 | */ |
||
424 | protected function setAndValidateVerbs($verbs) { |
||
446 | |||
447 | /** |
||
448 | * Set and validate the route name |
||
449 | * |
||
450 | * @param string $name Route name |
||
451 | * @throws InvalidArgumentException If the route name is empty |
||
452 | */ |
||
453 | protected function setAndValidateName($name) { |
||
463 | |||
464 | /** |
||
465 | * Set and validate the route path |
||
466 | * |
||
467 | * @param string $path Route path |
||
468 | * @throws InvalidArgumentException If the route path is empty |
||
469 | */ |
||
470 | protected function setAndValidatePath($path) { |
||
480 | |||
481 | /** |
||
482 | * Set and validate the route action |
||
483 | * |
||
484 | * @param string $action Route action |
||
485 | * @throws InvalidArgumentException If the route action is empty |
||
486 | * @throws InvalidArgumentException If the route action is not a class name |
||
487 | * @throws InvalidArgumentException If the route action is neither a callable nor an ActionInterface |
||
488 | */ |
||
489 | protected function setAndValidateAction($action) { |
||
534 | } |
||
535 |