From 7f3ad6625e00e39cad47cbfca97e6b872712d10a Mon Sep 17 00:00:00 2001 From: Sam Light Date: Wed, 10 Jun 2026 19:00:32 +0100 Subject: Route methods now return RouteDefinition class and testing --- src/RouteDefinition.php | 13 +++++++++++++ src/Router.php | 36 +++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 src/RouteDefinition.php (limited to 'src') diff --git a/src/RouteDefinition.php b/src/RouteDefinition.php new file mode 100644 index 0000000..ed6c721 --- /dev/null +++ b/src/RouteDefinition.php @@ -0,0 +1,13 @@ +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); } } -- cgit v1.2.3