1 | <?php |
||
18 | class Route |
||
19 | { |
||
20 | /** |
||
21 | * Router |
||
22 | * |
||
23 | * @var Router |
||
24 | */ |
||
25 | protected $router; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Continue propagation if match |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $continue_propagation = false; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * Route path |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $path; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Class to be instanced if route match was found |
||
46 | * |
||
47 | * @var string|object |
||
48 | */ |
||
49 | protected $class; |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Method to be executed if route match was found |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $method; |
||
58 | |||
59 | |||
60 | /** |
||
61 | * Found request parameters |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $params = []; |
||
66 | |||
67 | |||
68 | /** |
||
69 | * Instance route |
||
70 | * |
||
71 | * @param string $path |
||
72 | * @param string $class |
||
73 | * @param string $method |
||
74 | * @param array $params |
||
75 | * @return void |
||
|
|||
76 | */ |
||
77 | public function __construct(string $path, $class, ? string $method = null, array $params = []) |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Check if route does match the current http request |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function match(): bool |
||
113 | |||
114 | |||
115 | /** |
||
116 | * Get callable |
||
117 | * |
||
118 | * @param ContainerInterface $container |
||
119 | * @return array |
||
120 | */ |
||
121 | public function getCallable(?ContainerInterface $container=null): array |
||
139 | |||
140 | |||
141 | /** |
||
142 | * Build method name |
||
143 | * |
||
144 | * @param string $name |
||
145 | * @return string |
||
146 | */ |
||
147 | protected function buildMethodName(? string $name) : string |
||
160 | |||
161 | |||
162 | /** |
||
163 | * Get http router |
||
164 | * |
||
165 | * @return Router |
||
166 | */ |
||
167 | public function getRouter(): Router |
||
171 | |||
172 | |||
173 | /** |
||
174 | * Set http router |
||
175 | * |
||
176 | * @param Router $router |
||
177 | * @return Route |
||
178 | */ |
||
179 | public function setRouter(Router $router): Route |
||
184 | |||
185 | |||
186 | /** |
||
187 | * Get path |
||
188 | * |
||
189 | * @return string |
||
190 | */ |
||
191 | public function getPath(): string |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Set path |
||
199 | * |
||
200 | * @param string $path |
||
201 | * @return Route |
||
202 | */ |
||
203 | public function setPath(string $path): Route |
||
208 | |||
209 | |||
210 | /** |
||
211 | * Get class |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getClass(): string |
||
223 | |||
224 | |||
225 | /** |
||
226 | * Set clas |
||
227 | * |
||
228 | * @param string|object $class |
||
229 | * @return Route |
||
230 | */ |
||
231 | public function setClass($class): Route |
||
236 | |||
237 | |||
238 | /** |
||
239 | * Convert camelCase to dashes |
||
240 | * |
||
241 | * @param string $value |
||
242 | * @return string |
||
243 | */ |
||
244 | protected function camelCase2Dashes(string $value): string |
||
248 | |||
249 | |||
250 | /** |
||
251 | * Get method |
||
252 | * |
||
253 | * @return string |
||
254 | */ |
||
255 | public function getMethod(): string |
||
276 | |||
277 | |||
278 | /** |
||
279 | * Set method |
||
280 | * |
||
281 | * @param string $method |
||
282 | * @return Route |
||
283 | */ |
||
284 | public function setMethod(? string $method) : Route |
||
289 | |||
290 | |||
291 | /** |
||
292 | * Set params |
||
293 | * |
||
294 | * @param array $params |
||
295 | * @return Route |
||
296 | */ |
||
297 | public function setParams(array $params): Route |
||
302 | |||
303 | |||
304 | /** |
||
305 | * Get translated regex variable values |
||
306 | * |
||
307 | * @return array |
||
308 | */ |
||
309 | public function getParams(): array |
||
313 | |||
314 | |||
315 | /** |
||
316 | * Continue propagation after match |
||
317 | * |
||
318 | * @return bool |
||
319 | */ |
||
320 | public function continueAfterMatch(): bool |
||
324 | |||
325 | |||
326 | /** |
||
327 | * Halt propagation after match |
||
328 | * |
||
329 | * @param bool $next |
||
330 | * @return Route |
||
331 | */ |
||
332 | public function continuePropagation($next = true): Route |
||
337 | } |
||
338 |
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.