From 77d833ca211bdaf55abafaf84d2730e9793b95e7 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 5 Feb 2025 11:21:13 -0500 Subject: [PATCH] Update SegmentRouterTrait.php --- src/SegmentRouterTrait.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/SegmentRouterTrait.php b/src/SegmentRouterTrait.php index e0e0357..11ea2f3 100644 --- a/src/SegmentRouterTrait.php +++ b/src/SegmentRouterTrait.php @@ -63,13 +63,6 @@ trait SegmentRouterTrait // node is a reference to our current location in the node tree $node = $routes; - // if the URI is just a slash, we can return the handler for the root node - if ($uri === '/') { - return isset($node[$method]) - ? ['code' => 200, 'handler' => $node[$method], 'params' => null] - : ['code' => 405, 'handler' => null, 'params' => null]; - } - // params will hold any dynamic segments we find $params = []; foreach (explode('/', trim($uri, '/')) as $segment) { @@ -83,10 +76,15 @@ trait SegmentRouterTrait } } + // if the method doesn't exist, return 405 + if (! array_key_exists($method, $node)) { + return ['code' => 405, 'handler' => null, 'params' => []]; + } + // if we found a handler for the method, return it and any params. if not, return a 405 return isset($node[$method]) ? ['code' => 200, 'handler' => $node[$method], 'params' => $params] - : ['code' => 405, 'handler' => null, 'params' => []]; + : ['code' => 404, 'handler' => null, 'params' => []]; } /**