Optimizing the RouteCollection::getRoutes() method

Signed-off-by: Andrey Pyzhikov <5071@mail.ru>
This commit is contained in:
Andrey Pyzhikov 2022-04-23 03:22:31 +08:00
parent 64d315ecc9
commit 2c77ee5da6
No known key found for this signature in database
GPG Key ID: BA61560FB9B7B817

View File

@ -452,16 +452,12 @@ class RouteCollection implements RouteCollectionInterface
// we might need to do.
$this->discoverRoutes();
$routes = [];
$collection = [];
$routes = [];
if (isset($this->routes[$verb])) {
// Keep current verb's routes at the beginning, so they're matched
// before any of the generic, "add" routes.
if (isset($this->routes['*'])) {
$extraRules = array_diff_key($this->routes['*'], $this->routes[$verb]);
$collection = array_merge($this->routes[$verb], $extraRules);
}
$collection = $this->routes[$verb] + ($this->routes['*'] ?? []);
foreach ($collection as $r) {
$key = key($r['route']);