diff options
Diffstat (limited to 'src/Router.php')
| -rw-r--r-- | src/Router.php | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/Router.php b/src/Router.php index 9632c69..5757b35 100644 --- a/src/Router.php +++ b/src/Router.php @@ -114,8 +114,11 @@ class Router return $this->strategy->runRoute($call); } - public function route(HttpMethod $method, string $path, callable $handler): void - { + public function route( + HttpMethod $method, + string $path, + callable $handler, + ): RouteDefinition { $pathSplit = $this->splitPath($path); $seg = $this->root(); @@ -123,36 +126,39 @@ class Router $seg = $seg->child($v); } - $seg->addRoute(new Route($method, $handler)); + $route = new Route($method, $handler); + $seg->addRoute($route); + + return new RouteDefinition($this, $route); } - public function get(string $path, callable $handler): void + public function get(string $path, callable $handler): RouteDefinition { - $this->route(HttpMethod::Get, $path, $handler); + return $this->route(HttpMethod::Get, $path, $handler); } - public function post(string $path, callable $handler): void + public function post(string $path, callable $handler): RouteDefinition { - $this->route(HttpMethod::Post, $path, $handler); + return $this->route(HttpMethod::Post, $path, $handler); } - public function put(string $path, callable $handler): void + public function put(string $path, callable $handler): RouteDefinition { - $this->route(HttpMethod::Put, $path, $handler); + return $this->route(HttpMethod::Put, $path, $handler); } - public function patch(string $path, callable $handler): void + public function patch(string $path, callable $handler): RouteDefinition { - $this->route(HttpMethod::Patch, $path, $handler); + return $this->route(HttpMethod::Patch, $path, $handler); } - public function delete(string $path, callable $handler): void + public function delete(string $path, callable $handler): RouteDefinition { - $this->route(HttpMethod::Delete, $path, $handler); + return $this->route(HttpMethod::Delete, $path, $handler); } - public function any(string $path, callable $handler): void + public function any(string $path, callable $handler): RouteDefinition { - $this->route(HttpMethod::Any, $path, $handler); + return $this->route(HttpMethod::Any, $path, $handler); } } |
