1 | <?php declare(strict_types=1); |
||
11 | class Router extends RouteCollector implements |
||
12 | MiddlewareAwareInterface, |
||
13 | RouteCollectionInterface, |
||
14 | StrategyAwareInterface |
||
15 | { |
||
16 | use MiddlewareAwareTrait; |
||
17 | use RouteCollectionTrait; |
||
18 | use StrategyAwareTrait; |
||
19 | |||
20 | /** |
||
21 | * @var Route[] |
||
22 | */ |
||
23 | protected $routes = []; |
||
24 | |||
25 | /** |
||
26 | * @var Route[] |
||
27 | */ |
||
28 | protected $namedRoutes = []; |
||
29 | |||
30 | /** |
||
31 | * @var RouteGroup[] |
||
32 | */ |
||
33 | protected $groups = []; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $patternMatchers = [ |
||
39 | '/{(.+?):number}/' => '{$1:[0-9]+}', |
||
40 | '/{(.+?):word}/' => '{$1:[a-zA-Z]+}', |
||
41 | '/{(.+?):alphanum_dash}/' => '{$1:[a-zA-Z0-9-_]+}', |
||
42 | '/{(.+?):slug}/' => '{$1:[a-z0-9-]+}', |
||
43 | '/{(.+?):uuid}/' => '{$1:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}+}' |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * Constructor |
||
48 | * |
||
49 | * @param RouteParser $parser |
||
50 | * @param DataGenerator $generator |
||
51 | */ |
||
52 | 63 | public function __construct(?RouteParser $parser = null, ?DataGenerator $generator = null) |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 45 | public function map(string $method, string $path, $handler): Route |
|
72 | |||
73 | /** |
||
74 | * Add a group of routes to the collection |
||
75 | * |
||
76 | * @param string $prefix |
||
77 | * @param callable $group |
||
78 | * |
||
79 | * @return RouteGroup |
||
80 | */ |
||
81 | 12 | public function group(string $prefix, callable $group): RouteGroup |
|
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | 48 | public function dispatch(ServerRequestInterface $request): ResponseInterface |
|
114 | |||
115 | /** |
||
116 | * Prepare all routes, build name index and filter out none matching |
||
117 | * routes before being passed off to the parser. |
||
118 | * |
||
119 | * @param ServerRequestInterface $request |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | 48 | protected function prepRoutes(ServerRequestInterface $request): void |
|
157 | |||
158 | /** |
||
159 | * Build an index of named routes. |
||
160 | * |
||
161 | * @return void |
||
162 | */ |
||
163 | 54 | protected function buildNameIndex(): void |
|
172 | |||
173 | /** |
||
174 | * Process all groups |
||
175 | * |
||
176 | * Adds all of the group routes to the collection and determines if the group |
||
177 | * strategy should be be used. |
||
178 | * |
||
179 | * @param ServerRequestInterface $request |
||
180 | * |
||
181 | * @return void |
||
182 | */ |
||
183 | 48 | protected function processGroups(ServerRequestInterface $request): void |
|
200 | |||
201 | /** |
||
202 | * Get a named route |
||
203 | * |
||
204 | * @param string $name |
||
205 | * |
||
206 | * @return Route |
||
207 | * |
||
208 | * @throws InvalidArgumentException when no route of the provided name exists |
||
209 | */ |
||
210 | 6 | public function getNamedRoute(string $name): Route |
|
220 | |||
221 | /** |
||
222 | * Add a convenient pattern matcher to the internal array for use with all routes |
||
223 | * |
||
224 | * @param string $alias |
||
225 | * @param string $regex |
||
226 | * |
||
227 | * @return self |
||
228 | */ |
||
229 | 3 | public function addPatternMatcher(string $alias, string $regex): self |
|
238 | |||
239 | /** |
||
240 | * Replace word patterns with regex in route path |
||
241 | * |
||
242 | * @param string $path |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | 30 | protected function parseRoutePath(string $path): string |
|
250 | |||
251 | /** |
||
252 | * @return Route[] |
||
253 | */ |
||
254 | public function getRoutes(): array |
||
258 | |||
259 | /** |
||
260 | * @param Route $route |
||
|
|||
261 | */ |
||
262 | public function removeRoute(Route $routeToRemove): void |
||
270 | } |
||
271 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.