1 | <?php |
||
9 | class Dispatcher |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * Routes array to be registered. |
||
14 | * Some routes may have aliases to be used in templating system |
||
15 | * Route item can be defined using array key as an alias key. |
||
16 | * Each route item is an array has items respectively: Request Method, Request Uri, Controller/Action, Return Type. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | private $routes; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * Default return type if not noted in the $routes |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $defaultReturnType; |
||
29 | |||
30 | /** |
||
31 | * @var null|string |
||
32 | */ |
||
33 | private $cachedFile; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | private $routerClosures = []; |
||
39 | |||
40 | |||
41 | public function __construct(array $routes, int $defaultReturnType, ?string $cachedFile) |
||
47 | |||
48 | /** |
||
49 | * Dispatch against the provided HTTP method verb and URI. |
||
50 | * |
||
51 | * @return FastRoute\Dispatcher |
||
52 | * @throws RuntimeException; |
||
53 | */ |
||
54 | public function dispatcher() : FastRoute\Dispatcher |
||
71 | |||
72 | private function createCachedRoute($routeCollector) : void |
||
82 | |||
83 | /** |
||
84 | * @return FastRoute\Dispatcher\GroupCountBased |
||
85 | * @throws RuntimeException |
||
86 | */ |
||
87 | private function cachedDispatcher() : FastRoute\Dispatcher\GroupCountBased |
||
95 | |||
96 | /** |
||
97 | * Define Closures for all routes that returns controller info to be used. |
||
98 | * |
||
99 | * @param FastRoute\RouteCollector $route |
||
100 | */ |
||
101 | private function addRoutes(FastRoute\RouteCollector $route) : void |
||
111 | |||
112 | private function setRouteClosures() : void |
||
126 | |||
127 | |||
128 | |||
129 | /** |
||
130 | * Get route info for requested uri |
||
131 | * |
||
132 | * @param array $routeInfo |
||
133 | * @return array $routerData |
||
134 | */ |
||
135 | public function runDispatcher(array $routeInfo) : array |
||
151 | |||
152 | /** |
||
153 | * Get routeData according to dispatcher's results |
||
154 | * |
||
155 | * @param array $routeInfo |
||
156 | * @return array |
||
157 | */ |
||
158 | private function getRouteData(array $routeInfo) : array |
||
171 | } |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.