1 | <?php |
||
23 | class Router implements RouteableInterface |
||
24 | { |
||
25 | use Routeable, Bindable; |
||
26 | |||
27 | /** |
||
28 | * notFoundFuncName |
||
29 | * |
||
30 | * (default value: 'notFoundHandler') |
||
31 | * |
||
32 | * @var string |
||
33 | * @access protected |
||
34 | */ |
||
35 | protected $notFoundFuncName = 'notFoundHandler'; |
||
36 | |||
37 | /** |
||
38 | * forbiddenFuncName |
||
39 | * |
||
40 | * (default value: 'forbidenMethodHandler') |
||
41 | * |
||
42 | * @var string |
||
43 | * @access protected |
||
44 | */ |
||
45 | protected $forbiddenFuncName = 'forbidenMethodHandler'; |
||
46 | |||
47 | /** |
||
48 | * dispatch_result |
||
49 | * |
||
50 | * @var mixed |
||
51 | * @access protected |
||
52 | */ |
||
53 | protected $dispatch_result; |
||
54 | |||
55 | /** |
||
56 | * routes |
||
57 | * |
||
58 | * (default value: []) |
||
59 | * |
||
60 | * @var mixed |
||
61 | * @access protected |
||
62 | */ |
||
63 | protected $routes = []; |
||
64 | |||
65 | /** |
||
66 | * routeCount |
||
67 | * |
||
68 | * (default value: 0) |
||
69 | * |
||
70 | * @var int |
||
71 | * @access protected |
||
72 | */ |
||
73 | protected $routeCount = 0; |
||
74 | |||
75 | /** |
||
76 | * routeGroup |
||
77 | * |
||
78 | * @var mixed |
||
79 | * @access protected |
||
80 | */ |
||
81 | protected $routeGroup; |
||
82 | |||
83 | /** |
||
84 | * parser |
||
85 | * |
||
86 | * @var mixed |
||
87 | * @access protected |
||
88 | */ |
||
89 | protected $parser; |
||
90 | |||
91 | /** |
||
92 | * dispatcher |
||
93 | * |
||
94 | * @var mixed |
||
95 | * @access protected |
||
96 | */ |
||
97 | protected $dispatcher; |
||
98 | |||
99 | /** |
||
100 | * cachePool |
||
101 | * |
||
102 | * @var mixed |
||
103 | * @access protected |
||
104 | */ |
||
105 | protected $cachePool; |
||
106 | |||
107 | /** |
||
108 | * cacheKey |
||
109 | * |
||
110 | * (default value: "{Resilient\Router}/router.cache") |
||
111 | * |
||
112 | * @var string |
||
113 | * @access protected |
||
114 | */ |
||
115 | protected $cacheKey = "{Resilient\Router}/router.cache"; |
||
116 | |||
117 | /** |
||
118 | * cacheTtl |
||
119 | * |
||
120 | * (default value: 86400) |
||
121 | * |
||
122 | * @var int |
||
123 | * @access protected |
||
124 | */ |
||
125 | protected $cacheTtl = 86400; |
||
126 | |||
127 | /** |
||
128 | * apiHandler |
||
129 | * |
||
130 | * @var mixed |
||
131 | * @access protected |
||
132 | */ |
||
133 | protected $apiHandler; |
||
134 | |||
135 | /** |
||
136 | * notFoundHandler |
||
137 | * |
||
138 | * @var mixed |
||
139 | * @access protected |
||
140 | */ |
||
141 | protected $notFoundHandler; |
||
142 | |||
143 | /** |
||
144 | * methodNotAllowedHandler |
||
145 | * |
||
146 | * @var mixed |
||
147 | * @access protected |
||
148 | */ |
||
149 | protected $methodNotAllowedHandler; |
||
150 | |||
151 | /** |
||
152 | * __construct function. |
||
153 | * |
||
154 | * @access public |
||
155 | * @param mixed $parser |
||
156 | */ |
||
157 | public function __construct($parser) |
||
161 | |||
162 | /** |
||
163 | * setDispatcher function. |
||
164 | * |
||
165 | * @access public |
||
166 | * @param Dispatcher $dispatcher |
||
167 | * @return Router |
||
168 | */ |
||
169 | public function setDispatcher(Dispatcher $dispatcher) |
||
175 | |||
176 | /** |
||
177 | * setcachePool function. |
||
178 | * |
||
179 | * @access public |
||
180 | * @param CacheInterface $cachePool |
||
181 | * @return Router |
||
182 | */ |
||
183 | public function setCachePool(CacheItemPoolInterface $cachePool) |
||
184 | { |
||
185 | $this->cachePool = $cachePool; |
||
186 | |||
187 | return $this; |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * setCacheTtl function. |
||
192 | * |
||
193 | * @access public |
||
194 | * @param int $cacheTtl |
||
195 | * @return Router |
||
196 | */ |
||
197 | public function setCacheTtl(int $cacheTtl) |
||
203 | |||
204 | /** |
||
205 | * setCacheKey function. |
||
206 | * |
||
207 | * @access public |
||
208 | * @param string $cacheKey |
||
209 | * @return Router |
||
210 | */ |
||
211 | public function setCacheKey(string $cacheKey) |
||
216 | |||
217 | /** |
||
218 | * getRoute function. |
||
219 | * |
||
220 | * @access public |
||
221 | * @param string $identifier |
||
222 | * @return null|Route |
||
223 | */ |
||
224 | public function getRoute(string $identifier) |
||
228 | |||
229 | /** |
||
230 | * getRoutes function. |
||
231 | * |
||
232 | * @access public |
||
233 | * @return array |
||
234 | */ |
||
235 | public function getRoutes() |
||
239 | |||
240 | /** |
||
241 | * setRoutes function. |
||
242 | * |
||
243 | * @access public |
||
244 | * @param array $method |
||
245 | * @param array $routes |
||
246 | * @return Router |
||
247 | */ |
||
248 | public function setRoutes(array $method, array $routes) |
||
256 | |||
257 | /** |
||
258 | * getResult function. |
||
259 | * |
||
260 | * @access public |
||
261 | * @return void |
||
262 | */ |
||
263 | public function getResult() |
||
267 | |||
268 | /** |
||
269 | * {@inheritdoc} |
||
270 | */ |
||
271 | public function map($method, string $pattern, $handler) |
||
289 | |||
290 | /** |
||
291 | * createRoute function. |
||
292 | * |
||
293 | * @access protected |
||
294 | * @param string $method |
||
295 | * @param string $pattern |
||
296 | * @param mixed $handler |
||
297 | * @return Route Route |
||
298 | */ |
||
299 | protected function createRoute(string $method, string $pattern, $handler) |
||
303 | |||
304 | /** |
||
305 | * cacheAble function. |
||
306 | * |
||
307 | * @access protected |
||
308 | * @return void |
||
309 | */ |
||
310 | protected function cacheAble() |
||
314 | |||
315 | /** |
||
316 | * getCacheItem function. |
||
317 | * |
||
318 | * @access protected |
||
319 | * @return CacheItemInterface |
||
320 | */ |
||
321 | protected function getCacheItem() |
||
325 | |||
326 | /** |
||
327 | * routeDispatcher function. |
||
328 | * |
||
329 | * @access protected |
||
330 | * @param callable $routeDefinitionCallback |
||
331 | * @param array $options (default: []) |
||
332 | * @return Dispatcher |
||
333 | */ |
||
334 | protected function routeDispatcher(callable $routeDefinitionCallback, array $options = []) |
||
361 | |||
362 | /** |
||
363 | * createDispatcher function. |
||
364 | * |
||
365 | * @access protected |
||
366 | * @return Dispatcher |
||
367 | */ |
||
368 | protected function createDispatcher() |
||
384 | |||
385 | /** |
||
386 | * dispatch function. |
||
387 | * |
||
388 | * @access public |
||
389 | * @param UriInterface $uri |
||
390 | * @param string $method (default: 'GET') |
||
391 | * @return Route Handling Method |
||
392 | */ |
||
393 | public function dispatch(UriInterface $uri, $method = 'GET') |
||
421 | |||
422 | protected function handleException(string $handler, array $args, string $message) |
||
430 | |||
431 | /** |
||
432 | * whenNotFound function. |
||
433 | * |
||
434 | * @access public |
||
435 | * @param callable $callable |
||
436 | * @return Router |
||
437 | */ |
||
438 | public function whenNotFound(callable $callable) |
||
444 | |||
445 | /** |
||
446 | * whenForbidden function. |
||
447 | * |
||
448 | * @access public |
||
449 | * @param callable $callable |
||
450 | * @return Router |
||
451 | */ |
||
452 | public function whenForbidden(callable $callable) |
||
458 | |||
459 | /** |
||
460 | * routerRoutine function. |
||
461 | * |
||
462 | * @access protected |
||
463 | * @param mixed $identifier |
||
464 | * @param mixed $args |
||
465 | * @return void |
||
466 | */ |
||
467 | protected function routerRoutine($identifier, $args) |
||
483 | } |
||
484 |
This check looks for function calls that miss required arguments.