add defaults to lookup result array

This commit is contained in:
Sky Johnson 2024-09-19 12:46:46 -05:00
parent 60baec0c53
commit 1d44e8540d
2 changed files with 4 additions and 4 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "sharkk/router", "name": "sharkk/router",
"description": "A simple node-based router.", "description": "A simple node-based router.",
"version": "1.1.3", "version": "1.1.4",
"type": "library", "type": "library",
"license": "MIT", "license": "MIT",
"autoload": { "autoload": {

View File

@ -40,7 +40,7 @@ class SegmentRouter implements Router
if ($uri === '/') { if ($uri === '/') {
return isset($node[$method]) return isset($node[$method])
? ['code' => 200, 'handler' => $node[$method], 'params' => null] ? ['code' => 200, 'handler' => $node[$method], 'params' => null]
: ['code' => 405]; : ['code' => 405, 'handler' => null, 'params' => null];
} }
// We'll split up the URI into segments and traverse the node tree // We'll split up the URI into segments and traverse the node tree
@ -59,13 +59,13 @@ class SegmentRouter implements Router
} }
// if we can't find a node for this segment, return 404 // if we can't find a node for this segment, return 404
return ['code' => 404]; return ['code' => 404, 'handler' => null, 'params' => null];
} }
// if we found a handler for the method, return it and any params. if not, return a 405 // if we found a handler for the method, return it and any params. if not, return a 405
return isset($node[$method]) return isset($node[$method])
? ['code' => 200, 'handler' => $node[$method], 'params' => $params ?? null] ? ['code' => 200, 'handler' => $node[$method], 'params' => $params ?? null]
: ['code' => 405]; : ['code' => 405, 'handler' => null, 'params' => null];
} }
public function clear(): Router public function clear(): Router