1 | <?php |
||
20 | class Router |
||
21 | { |
||
22 | /** |
||
23 | * Requested route |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $path; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * HTTP verb |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $verb; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Installed routes |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $routes = []; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Logger |
||
48 | * |
||
49 | * @var Logger |
||
50 | */ |
||
51 | protected $logger; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Init router |
||
56 | * |
||
57 | * @param array $server |
||
58 | * @param Logger $logger |
||
59 | * @return void |
||
|
|||
60 | */ |
||
61 | public function __construct(array $server, Logger $logger) |
||
73 | |||
74 | /** |
||
75 | * Add route to the beginning of the routing table |
||
76 | * |
||
77 | * @param Route $route |
||
78 | * @return Router |
||
79 | */ |
||
80 | public function prependRoute(Route $route): Router |
||
86 | |||
87 | |||
88 | /** |
||
89 | * Add route to the end of the routing table |
||
90 | * |
||
91 | * @param Route $route |
||
92 | * @return Router |
||
93 | */ |
||
94 | public function appendRoute(Route $route): Router |
||
100 | |||
101 | |||
102 | /** |
||
103 | * Clear routing table |
||
104 | * |
||
105 | * @return Router |
||
106 | */ |
||
107 | public function clearRoutingTable(): Router |
||
112 | |||
113 | |||
114 | /** |
||
115 | * Get active routes |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function getRoutes(): array |
||
123 | |||
124 | |||
125 | /** |
||
126 | * Set HTTP verb |
||
127 | * |
||
128 | * @param string $verb |
||
129 | * @return Router |
||
130 | */ |
||
131 | public function setVerb(string $verb): Router |
||
136 | |||
137 | |||
138 | /** |
||
139 | * Get http verb |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getVerb(): string |
||
147 | |||
148 | |||
149 | /** |
||
150 | * Set routing path |
||
151 | * |
||
152 | * @param string $path |
||
153 | * @return Router |
||
154 | */ |
||
155 | public function setPath(string $path): Router |
||
161 | |||
162 | |||
163 | /** |
||
164 | * Get path |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getPath(): string |
||
172 | |||
173 | |||
174 | /** |
||
175 | * Build method name |
||
176 | * |
||
177 | * @param string $name |
||
178 | * @return string |
||
179 | */ |
||
180 | protected function _buildMethodName(string $name): string |
||
190 | |||
191 | |||
192 | /** |
||
193 | * Execute router |
||
194 | * |
||
195 | * @param array $constructor |
||
196 | * @return bool |
||
197 | */ |
||
198 | public function run(array $constructor = []): bool |
||
253 | |||
254 | |||
255 | /** |
||
256 | * Sends a exception response to the client |
||
257 | * |
||
258 | * @param \Exception $exception |
||
259 | * @return void |
||
260 | */ |
||
261 | public function sendException(\Exception $exception): void |
||
280 | |||
281 | |||
282 | /** |
||
283 | * Check if method got params and combine these with |
||
284 | * $_REQUEST |
||
285 | * |
||
286 | * @param string $class |
||
287 | * @param string $method |
||
288 | * @param array $parsed_params |
||
289 | * @return callable |
||
290 | */ |
||
291 | protected function getParams(string $class, string $method, array $parsed_params): array |
||
351 | } |
||
352 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.