-
Notifications
You must be signed in to change notification settings - Fork 0
/
CastRouteCollector.php
47 lines (39 loc) · 1.28 KB
/
CastRouteCollector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace CastRoute;
use FastRoute\DataGenerator;
use FastRoute\RouteCollector;
use FastRoute\RouteParser;
class CastRouteCollector extends RouteCollector
{
protected CastRouteHandlers $routeHandlers;
protected CastRouteVariables $routeVariables;
public function __construct(
RouteParser $routeParser,
DataGenerator $dataGenerator,
CastRouteHandlers $routeHandlers,
CastRouteVariables $routeVariables,
) {
parent::__construct($routeParser, $dataGenerator);
$this->routeHandlers = $routeHandlers;
$this->routeVariables = $routeVariables;
}
/**
* @inheritdoc
*/
public function addRoute($httpMethod, $route, $handler) : void
{
$route = $this->currentGroupPrefix . $route;
$fixed = $this->routeVariables->fixRoute($route);
$routeDatas = $this->routeParser->parse($fixed);
foreach ((array) $httpMethod as $method) {
foreach ($routeDatas as $routeData) {
$this->dataGenerator->addRoute($method, $routeData, $handler);
}
if (is_string($handler)) {
$this->routeHandlers
->setHandler($handler, $method, $route, $routeDatas);
}
}
}
}