1
<?php declare(strict_types=1);
3
namespace Upside\Router;
5
final class RouteCollector implements RouteCollectorInterface
10
private array $routes = [];
13
* @param class-string $controller
15
public function add_route(string $path, string $controller, string $action, string $method, string $name): void
17
$this->route(new Route($path, $controller, $action, $method, $name));
21
* @param class-string $controller
24
public function get(string $path, string $controller, string $action, string $name): void
26
$this->add_route($path, $controller, $action, 'GET', $name);
30
* @param class-string $controller
33
public function post(string $path, string $controller, string $action, string $name): void
35
$this->add_route($path, $controller, $action, 'POST', $name);
39
* @param class-string $controller
42
public function put(string $path, string $controller, string $action, string $name): void
44
$this->add_route($path, $controller, $action, 'PUT', $name);
48
* @param class-string $controller
51
public function delete(string $path, string $controller, string $action, string $name): void
53
$this->add_route($path, $controller, $action, 'DELETE', $name);
57
* @param class-string $controller
60
public function patch(string $path, string $controller, string $action, string $name): void
62
$this->add_route($path, $controller, $action, 'PATCH', $name);
66
* @param class-string $controller
69
public function head(string $path, string $controller, string $action, string $name): void
71
$this->add_route($path, $controller, $action, 'HEAD', $name);
75
* @param class-string $controller
78
public function options(string $path, string $controller, string $action, string $name): void
80
$this->add_route($path, $controller, $action, 'OPTIONS', $name);
84
public function route(Route $route): self
86
$this->routes[$route->name] = $route;
95
public function routes(): array