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;