1 | <?php |
||
23 | class RouteCollection extends RouteCollector implements |
||
24 | MiddlewareAwareInterface, |
||
25 | RouteCollectionInterface, |
||
26 | StrategyAwareInterface |
||
27 | { |
||
28 | use MiddlewareAwareTrait; |
||
29 | use RouteCollectionMapTrait; |
||
30 | use StrategyAwareTrait; |
||
31 | |||
32 | /** |
||
33 | * @var \Psr\Container\ContainerInterface |
||
34 | */ |
||
35 | protected $container; |
||
36 | |||
37 | /** |
||
38 | * @var \League\Route\Route[] |
||
39 | */ |
||
40 | protected $routes = []; |
||
41 | |||
42 | /** |
||
43 | * @var \League\Route\Route[] |
||
44 | */ |
||
45 | protected $namedRoutes = []; |
||
46 | |||
47 | /** |
||
48 | * @var \League\Route\RouteGroup[] |
||
49 | */ |
||
50 | protected $groups = []; |
||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $patternMatchers = [ |
||
56 | '/{(.+?):number}/' => '{$1:[0-9]+}', |
||
57 | '/{(.+?):word}/' => '{$1:[a-zA-Z]+}', |
||
58 | '/{(.+?):alphanum_dash}/' => '{$1:[a-zA-Z0-9-_]+}', |
||
59 | '/{(.+?):slug}/' => '{$1:[a-z0-9-]+}', |
||
60 | '/{(.+?):uuid}/' => '{$1:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}+}' |
||
61 | ]; |
||
62 | |||
63 | /** |
||
64 | * Constructor. |
||
65 | * |
||
66 | * @param \Psr\Container\ContainerInterface $container |
||
67 | * @param \FastRoute\RouteParser $parser |
||
68 | * @param \FastRoute\DataGenerator $generator |
||
69 | */ |
||
70 | 45 | public function __construct( |
|
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 30 | public function map($method, $path, $handler) |
|
95 | |||
96 | /** |
||
97 | * Add a group of routes to the collection. |
||
98 | * |
||
99 | * @param string $prefix |
||
100 | * @param callable $group |
||
101 | * |
||
102 | * @return \League\Route\RouteGroup |
||
103 | */ |
||
104 | 6 | public function group($prefix, callable $group) |
|
111 | |||
112 | /** |
||
113 | * Dispatch the route based on the request. |
||
114 | * |
||
115 | * @param \Psr\Http\Message\ServerRequestInterface $request |
||
116 | * @param \Psr\Http\Message\ResponseInterface $response |
||
117 | * |
||
118 | * @return \Psr\Http\Message\ResponseInterface |
||
119 | */ |
||
120 | 24 | public function dispatch(ServerRequestInterface $request, ResponseInterface $response) |
|
136 | |||
137 | /** |
||
138 | * Return a fully configured dispatcher. |
||
139 | * |
||
140 | * @param \Psr\Http\Message\ServerRequestInterface $request |
||
141 | * |
||
142 | * @return \League\Route\Dispatcher |
||
143 | */ |
||
144 | 27 | public function getDispatcher(ServerRequestInterface $request) |
|
157 | |||
158 | /** |
||
159 | * @return bool |
||
160 | */ |
||
161 | public function isRoutesPrepared() |
||
165 | 27 | ||
166 | /** |
||
167 | 27 | * Prepare all routes, build name index and filter out none matching |
|
168 | * routes before being passed off to the parser. |
||
169 | 27 | * |
|
170 | * @param \Psr\Http\Message\ServerRequestInterface $request |
||
171 | 21 | * |
|
172 | 3 | * @return void |
|
173 | */ |
||
174 | protected function prepRoutes(ServerRequestInterface $request) |
||
204 | 27 | ||
205 | 6 | /** |
|
206 | 6 | * Build an index of named routes. |
|
207 | 6 | * |
|
208 | 36 | * @return void |
|
209 | 36 | */ |
|
210 | protected function buildNameIndex() |
||
221 | 36 | ||
222 | 36 | /** |
|
223 | * Process all groups. |
||
224 | * |
||
225 | * @return void |
||
226 | */ |
||
227 | protected function processGroups() |
||
234 | |||
235 | 9 | /** |
|
236 | 6 | * Get named route. |
|
237 | * |
||
238 | * @param string $name |
||
239 | 3 | * |
|
240 | * @return \League\Route\Route |
||
241 | */ |
||
242 | public function getNamedRoute($name) |
||
252 | 3 | ||
253 | 3 | /** |
|
254 | * Add a convenient pattern matcher to the internal array for use with all routes. |
||
255 | 3 | * |
|
256 | 3 | * @param string $alias |
|
257 | * @param string $regex |
||
258 | * |
||
259 | * @return void |
||
260 | */ |
||
261 | public function addPatternMatcher($alias, $regex) |
||
268 | |||
269 | /** |
||
270 | * Convenience method to convert pre-defined key words in to regex strings. |
||
271 | * |
||
272 | * @param string $path |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | protected function parseRoutePath($path) |
||
280 | } |
||
281 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: