forked from PHP/Router
Update SegmentRouterTrait.php
This commit is contained in:
parent
77d833ca21
commit
a395b7ae17
|
@ -63,6 +63,10 @@ trait SegmentRouterTrait
|
||||||
// node is a reference to our current location in the node tree
|
// node is a reference to our current location in the node tree
|
||||||
$node = $routes;
|
$node = $routes;
|
||||||
|
|
||||||
|
if ($uri === '/' && isset($node[$method]) && array_key_exists($method, $node)) {
|
||||||
|
return ['code' => 200, 'handler' => $node[$method], 'params' => null];
|
||||||
|
}
|
||||||
|
|
||||||
// params will hold any dynamic segments we find
|
// params will hold any dynamic segments we find
|
||||||
$params = [];
|
$params = [];
|
||||||
foreach (explode('/', trim($uri, '/')) as $segment) {
|
foreach (explode('/', trim($uri, '/')) as $segment) {
|
||||||
|
@ -82,9 +86,7 @@ trait SegmentRouterTrait
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 ['code' => 200, 'handler' => $node[$method], 'params' => $params];
|
||||||
? ['code' => 200, 'handler' => $node[$method], 'params' => $params]
|
|
||||||
: ['code' => 404, 'handler' => null, 'params' => []];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user