Faster early returns
This commit is contained in:
parent
ccb5a236a0
commit
9fdef6b250
|
@ -63,11 +63,9 @@ 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];
|
||||
// if the URI is the root, and the method is defined, return the handler
|
||||
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
|
||||
|
@ -84,9 +82,11 @@ trait SegmentRouterTrait
|
|||
}
|
||||
|
||||
// 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' => []];
|
||||
if (array_key_exists($method, $node)) {
|
||||
return ['code' => 200, 'handler' => $node[$method], 'params' => $params];
|
||||
}
|
||||
|
||||
return ['code' => 405, 'handler' => null, 'params' => []];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user