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 \League\Route\Route[] |
||
22 | */ |
||
23 | protected $routes = []; |
||
24 | |||
25 | /** |
||
26 | * @var \League\Route\Route[] |
||
27 | */ |
||
28 | protected $namedRoutes = []; |
||
29 | |||
30 | /** |
||
31 | * @var \League\Route\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 ?\FastRoute\RouteParser $parser |
||
|
|||
50 | * @param ?\FastRoute\DataGenerator $generator |
||
51 | */ |
||
52 | 39 | public function __construct(?RouteParser $parser = null, ?DataGenerator $generator = null) |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 24 | 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 \League\Route\RouteGroup |
||
80 | */ |
||
81 | 3 | public function group(string $prefix, callable $group) : RouteGroup |
|
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | 24 | public function dispatch(ServerRequestInterface $request) : ResponseInterface |
|
106 | |||
107 | /** |
||
108 | * Prepare all routes, build name index and filter out none matching |
||
109 | * routes before being passed off to the parser. |
||
110 | * |
||
111 | * @param \Psr\Http\Message\ServerRequestInterface $request |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | 24 | protected function prepRoutes(ServerRequestInterface $request) : void |
|
145 | |||
146 | /** |
||
147 | * Build an index of named routes. |
||
148 | * |
||
149 | * @return void |
||
150 | */ |
||
151 | 30 | protected function buildNameIndex() : void |
|
160 | |||
161 | /** |
||
162 | * Process all groups, and determine if we are using a group's strategy. |
||
163 | * |
||
164 | * @param ?\Psr\Http\Message\ServerRequestInterface $request |
||
165 | * |
||
166 | * @return void |
||
167 | */ |
||
168 | 24 | protected function processGroups(?ServerRequestInterface $request = null) : void |
|
185 | |||
186 | /** |
||
187 | * Get named route. |
||
188 | * |
||
189 | * @param string $name |
||
190 | * |
||
191 | * @throws \InvalidArgumentException when no route of the provided name exists. |
||
192 | * |
||
193 | * @return \League\Route\Route |
||
194 | */ |
||
195 | 6 | public function getNamedRoute(string $name) : Route |
|
205 | |||
206 | /** |
||
207 | * Add a convenient pattern matcher to the internal array for use with all routes. |
||
208 | * |
||
209 | * @param string $alias |
||
210 | * @param string $regex |
||
211 | * |
||
212 | * @return self |
||
213 | */ |
||
214 | 3 | public function addPatternMatcher(string $alias, string $regex) : self |
|
223 | |||
224 | /** |
||
225 | * Convenience method to convert pre-defined key words in to regex strings. |
||
226 | * |
||
227 | * @param string $path |
||
228 | * |
||
229 | * @return string |
||
230 | */ |
||
231 | 18 | protected function parseRoutePath(string $path) : string |
|
235 | } |
||
236 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.