1 | <?php |
||
24 | class Router implements RouteableInterface |
||
25 | { |
||
26 | use Routeable, Bindable; |
||
27 | |||
28 | /** |
||
29 | * notFoundFuncName |
||
30 | * |
||
31 | * (default value: 'notFoundHandler') |
||
32 | * |
||
33 | * @var string |
||
34 | * @access protected |
||
35 | */ |
||
36 | protected $notFoundFuncName = 'notFoundHandler'; |
||
37 | |||
38 | /** |
||
39 | * forbiddenFuncName |
||
40 | * |
||
41 | * (default value: 'forbidenMethodHandler') |
||
42 | * |
||
43 | * @var string |
||
44 | * @access protected |
||
45 | */ |
||
46 | protected $forbiddenFuncName = 'forbidenMethodHandler'; |
||
47 | |||
48 | /** |
||
49 | * dispatch_result |
||
50 | * |
||
51 | * @var mixed |
||
52 | * @access protected |
||
53 | */ |
||
54 | protected $dispatch_result; |
||
55 | |||
56 | /** |
||
57 | * routes |
||
58 | * |
||
59 | * (default value: []) |
||
60 | * |
||
61 | * @var mixed |
||
62 | * @access protected |
||
63 | */ |
||
64 | protected $routes = []; |
||
65 | |||
66 | /** |
||
67 | * routeCount |
||
68 | * |
||
69 | * (default value: 0) |
||
70 | * |
||
71 | * @var int |
||
72 | * @access protected |
||
73 | */ |
||
74 | protected $routeCount = 0; |
||
75 | |||
76 | /** |
||
77 | * routeGroup |
||
78 | * |
||
79 | * @var mixed |
||
80 | * @access protected |
||
81 | */ |
||
82 | protected $routeGroup; |
||
83 | |||
84 | /** |
||
85 | * parser |
||
86 | * |
||
87 | * @var mixed |
||
88 | * @access protected |
||
89 | */ |
||
90 | protected $parser; |
||
91 | |||
92 | /** |
||
93 | * dispatcher |
||
94 | * |
||
95 | * @var mixed |
||
96 | * @access protected |
||
97 | */ |
||
98 | protected $dispatcher; |
||
99 | |||
100 | /** |
||
101 | * cachePool |
||
102 | * |
||
103 | * @var mixed |
||
104 | * @access protected |
||
105 | */ |
||
106 | protected $cachePool; |
||
107 | |||
108 | /** |
||
109 | * cacheKey |
||
110 | * |
||
111 | * (default value: "{Resilient\Router}/router.cache") |
||
112 | * |
||
113 | * @var string |
||
114 | * @access protected |
||
115 | */ |
||
116 | protected $cacheKey = "router.cache"; |
||
117 | |||
118 | /** |
||
119 | * cacheTtl |
||
120 | * |
||
121 | * (default value: 86400) |
||
122 | * |
||
123 | * @var int |
||
124 | * @access protected |
||
125 | */ |
||
126 | protected $cacheTtl = 86400; |
||
127 | |||
128 | /** |
||
129 | * apiHandler |
||
130 | * |
||
131 | * @var mixed |
||
132 | * @access protected |
||
133 | */ |
||
134 | protected $apiHandler; |
||
135 | |||
136 | /** |
||
137 | * notFoundHandler |
||
138 | * |
||
139 | * @var mixed |
||
140 | * @access protected |
||
141 | */ |
||
142 | protected $notFoundHandler; |
||
143 | |||
144 | /** |
||
145 | * methodNotAllowedHandler |
||
146 | * |
||
147 | * @var mixed |
||
148 | * @access protected |
||
149 | */ |
||
150 | protected $methodNotAllowedHandler; |
||
151 | |||
152 | /** |
||
153 | * __construct function. |
||
154 | * |
||
155 | * @access public |
||
156 | * @param mixed $parser |
||
157 | */ |
||
158 | public function __construct($parser) |
||
162 | |||
163 | /** |
||
164 | * setDispatcher function. |
||
165 | * |
||
166 | * @access public |
||
167 | * @param Dispatcher $dispatcher |
||
168 | * @return Router |
||
169 | */ |
||
170 | public function setDispatcher(Dispatcher $dispatcher) |
||
176 | |||
177 | /** |
||
178 | * setcachePool function. |
||
179 | * |
||
180 | * @access public |
||
181 | * @param CacheItemPoolInterface $cachePool |
||
182 | * @return Router |
||
183 | */ |
||
184 | public function setCachePool(CacheItemPoolInterface $cachePool) |
||
190 | |||
191 | /** |
||
192 | * setCacheTtl function. |
||
193 | * |
||
194 | * @access public |
||
195 | * @param int $cacheTtl |
||
196 | * @return Router |
||
197 | */ |
||
198 | public function setCacheTtl(int $cacheTtl) |
||
204 | |||
205 | /** |
||
206 | * setCacheKey function. |
||
207 | * |
||
208 | * @access public |
||
209 | * @param string $cacheKey |
||
210 | * @return Router |
||
211 | */ |
||
212 | public function setCacheKey(string $cacheKey) |
||
217 | |||
218 | /** |
||
219 | * getRoute function. |
||
220 | * |
||
221 | * @access public |
||
222 | * @param string $identifier |
||
223 | * @return null|Route |
||
224 | */ |
||
225 | public function getRoute(string $identifier) |
||
229 | |||
230 | /** |
||
231 | * getRoutes function. |
||
232 | * |
||
233 | * @access public |
||
234 | * @return array |
||
235 | */ |
||
236 | public function getRoutes() |
||
240 | |||
241 | /** |
||
242 | * setRoutes function. |
||
243 | * |
||
244 | * @access public |
||
245 | * @param array $method |
||
246 | * @param array $routes |
||
247 | * @return Router |
||
248 | */ |
||
249 | public function setRoutes(array $method, array $routes) |
||
257 | |||
258 | /** |
||
259 | * getResult function. |
||
260 | * |
||
261 | * @access public |
||
262 | * @return void |
||
263 | */ |
||
264 | public function getResult() |
||
268 | |||
269 | /** |
||
270 | * {@inheritdoc} |
||
271 | */ |
||
272 | public function map($method, string $pattern, $handler) |
||
290 | |||
291 | /** |
||
292 | * createRoute function. |
||
293 | * |
||
294 | * @access protected |
||
295 | * @param string $method |
||
296 | * @param string $pattern |
||
297 | * @param mixed $handler |
||
298 | * @return Route Route |
||
299 | */ |
||
300 | protected function createRoute(string $method, string $pattern, $handler) |
||
304 | |||
305 | /** |
||
306 | * cacheAble function. |
||
307 | * |
||
308 | * @access protected |
||
309 | * @return boolean |
||
310 | */ |
||
311 | protected function cacheAble() |
||
315 | |||
316 | /** |
||
317 | * getCacheItem function. |
||
318 | * |
||
319 | * @access protected |
||
320 | * @return CacheItemInterface |
||
321 | */ |
||
322 | protected function getCacheItem() |
||
326 | |||
327 | /** |
||
328 | * saveCacheItem function. |
||
329 | * |
||
330 | * @access protected |
||
331 | * @param CacheItemInterface $cacheItem |
||
332 | * @return boolean |
||
333 | */ |
||
334 | protected function saveCacheItem(CacheItemInterface $cacheItem) |
||
346 | |||
347 | /** |
||
348 | * routeDispatcher function. |
||
349 | * |
||
350 | * @access protected |
||
351 | * @param callable $routeDefinitionCallback |
||
352 | * @param array $options (default: []) |
||
353 | * @return Dispatcher |
||
354 | */ |
||
355 | protected function routeDispatcher(callable $routeDefinitionCallback, array $options = []) |
||
383 | |||
384 | /** |
||
385 | * createDispatcher function. |
||
386 | * |
||
387 | * @access protected |
||
388 | * @return Dispatcher |
||
389 | */ |
||
390 | protected function createDispatcher() |
||
406 | |||
407 | /** |
||
408 | * dispatch function. |
||
409 | * |
||
410 | * @access public |
||
411 | * @param UriInterface $uri |
||
412 | * @param string $method (default: 'GET') |
||
413 | * @return Route Handling Method |
||
414 | */ |
||
415 | public function dispatch(UriInterface $uri, $method = 'GET') |
||
445 | |||
446 | protected function handleException(string $handler, array $args, string $message) |
||
454 | |||
455 | /** |
||
456 | * whenNotFound function. |
||
457 | * |
||
458 | * @access public |
||
459 | * @param callable $callable |
||
460 | * @return Router |
||
461 | */ |
||
462 | public function whenNotFound(callable $callable) |
||
468 | |||
469 | /** |
||
470 | * whenForbidden function. |
||
471 | * |
||
472 | * @access public |
||
473 | * @param callable $callable |
||
474 | * @return Router |
||
475 | */ |
||
476 | public function whenForbidden(callable $callable) |
||
482 | |||
483 | /** |
||
484 | * routerRoutine function. |
||
485 | * |
||
486 | * @access protected |
||
487 | * @param mixed $identifier |
||
488 | * @param mixed $args |
||
489 | * @return void |
||
490 | */ |
||
491 | protected function routerRoutine($identifier, $args) |
||
507 | } |
||
508 |