From 4f5f2599f5fc6da840f463074e8131b4a66e129b Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 25 Dec 2024 10:22:33 -0500 Subject: [PATCH] Update SegmentRouter.php --- src/SegmentRouter.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/SegmentRouter.php b/src/SegmentRouter.php index f0bc6ef..a149d33 100644 --- a/src/SegmentRouter.php +++ b/src/SegmentRouter.php @@ -15,13 +15,16 @@ class SegmentRouter implements RouterInterface */ public function add(string $method, string $route, callable $handler): RouterInterface { - // Expand the route into segments and make dynamic segments into a common placeholder - $segments = array_map(function($segment) { - return str_starts_with($segment, ':') ? ':x' : $segment; - }, explode('/', trim($route, '/'))); - // Recursively build the node tree - $this->addNode($this->routes, $segments, $method, $handler); + $this->addNode( + $this->routes, + array_map( // Expand the route into segments and make dynamic segments into a common placeholder + fn($segment) => str_starts_with($segment, ':') ? ':x' : $segment, + explode('/', trim($route, '/')) + ), + $method, + $handler + ); // Add the handler to the last node $node[$method] = $handler;