From 1c58ff3a599672b333269dd7d1b5a89e1296e7ea Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 25 Dec 2024 10:59:20 -0500 Subject: [PATCH] Trait, Interface, Class --- src/SegmentRouter.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/SegmentRouter.php b/src/SegmentRouter.php index 6974837..f3424cd 100644 --- a/src/SegmentRouter.php +++ b/src/SegmentRouter.php @@ -2,10 +2,8 @@ namespace Sharkk\Router; -class SegmentRouter implements RouterInterface +trait SegmentRouterTrait { - private array $routes = []; - /** * Add a route to the route tree. The route must be a URI path, and contain dynamic segments * using a colon prefix. (:id, :slug, etc) @@ -172,3 +170,23 @@ class SegmentRouter implements RouterInterface return $this->add('HEAD', $route, $handler); } } + +interface SegmentRouterInterface extends RouterInterface +{ + //private function addNode(array &$node, array $segments, string $method, callable $handler): void; + public function clear(): RouterInterface; + public function dump(): array; + public function get(string $route, callable $handler): RouterInterface; + public function post(string $route, callable $handler): RouterInterface; + public function put(string $route, callable $handler): RouterInterface; + public function patch(string $route, callable $handler): RouterInterface; + public function delete(string $route, callable $handler): RouterInterface; + public function head(string $route, callable $handler): RouterInterface; +} + +class SegmentRouter implements SegmentRouterInterface +{ + private array $routes = []; + + use SegmentRouterTrait; +}