| Total Complexity | 8 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class Router implements RouterInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var RouterContainer |
||
| 12 | */ |
||
| 13 | private $routeContainer; |
||
| 14 | |||
| 15 | public function __construct() |
||
| 16 | { |
||
| 17 | $this->routeContainer = new RouterContainer(); |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Register a GET route. |
||
| 22 | * |
||
| 23 | * @param callable|string $action |
||
| 24 | */ |
||
| 25 | public function get(string $path, string $name, $action): Route |
||
| 26 | { |
||
| 27 | $route = $this->createRoute($path, $name, $action); |
||
| 28 | $route->allows('GET'); |
||
| 29 | return $this->routeContainer->addRoute($route); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Compare the given request with routes in the routerContainer. |
||
| 34 | */ |
||
| 35 | public function match(ServerRequestInterface $request): ?Route |
||
| 48 | } |
||
| 49 | |||
| 50 | public function getRoutes() |
||
| 51 | { |
||
| 52 | return $this->routeContainer->getRoutes(); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Create a new route. |
||
| 57 | * |
||
| 58 | * @param callable|string $action |
||
| 59 | */ |
||
| 60 | private function createRoute(string $path, string $name, $action): Route |
||
| 63 | } |
||
| 64 | } |
||
| 65 |