1 | <?php |
||
14 | class Router |
||
15 | { |
||
16 | /** @var RouteDefinitionProvider The route definition provider */ |
||
17 | private $provider; |
||
18 | |||
19 | /** @var string[] List of methods that would be allowed for the routed path */ |
||
20 | private $allowedMethods; |
||
21 | |||
22 | /** |
||
23 | * Router constructor. |
||
24 | * @param RouteDefinitionProvider $provider The route definition provider |
||
25 | */ |
||
26 | 18 | public function __construct(RouteDefinitionProvider $provider) |
|
31 | |||
32 | /** |
||
33 | * Routes the given path with the given HTTP request method to a specific route. |
||
34 | * @param string $method The HTTP request method |
||
35 | * @param string $path The decoded request path |
||
36 | * @return Route Matching route |
||
37 | * @throws MethodNotAllowedException If the path matches at least one route, but the method is not allowed |
||
38 | * @throws RouteNotFoundException If no route matches the given path |
||
39 | */ |
||
40 | 18 | public function route(string $method, string $path): Route |
|
72 | |||
73 | /** |
||
74 | * Returns routes that match the given HTTP request method and path segments. |
||
75 | * @param string $method The HTTP request method |
||
76 | * @param string[] $segments The requested path segments |
||
77 | * @return Route[] List of matching routes |
||
78 | */ |
||
79 | 17 | private function matchRoutes(string $method, array $segments): array |
|
95 | |||
96 | /** |
||
97 | * Returns a list of route ids for routes that have matching static path segments. |
||
98 | * @param string[] $segments The requested path segments |
||
99 | * @return int[] List of route ids for routes that have matching static path segments |
||
100 | */ |
||
101 | 11 | private function getIntersectingIds(array $segments): array |
|
121 | |||
122 | /** |
||
123 | * Returns the routes for the given ids that match the requested method and segments. |
||
124 | * @param int[] $ids List of route ids to match |
||
125 | * @param string $method The HTTP request method |
||
126 | * @param string[] $segments The requested path segments |
||
127 | * @return Route[] List of matching routes |
||
128 | */ |
||
129 | 17 | private function getMatchingRoutes(array $ids, string $method, array $segments): array |
|
151 | |||
152 | /** |
||
153 | * Returns the encoded URL for the route with the given name. |
||
154 | * @param string $name Name of the route |
||
155 | * @param string[] $parameters Values for the route parameters |
||
156 | * @return string The encoded URL for the route |
||
157 | */ |
||
158 | 9 | public function generateUrl(string $name, array $parameters = []): string |
|
163 | } |
||
164 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.