Skip to content

Commit 5583b8e

Browse files
[12.x] optimize AbstractRouteCollection@matchAgainstRoute() (#57871)
* optimize matchAgainstRoute * Add fallback route handling in route matching --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent bc808fe commit 5583b8e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Illuminate/Routing/AbstractRouteCollection.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,21 @@ function ($method) use ($request) {
7979
*/
8080
protected function matchAgainstRoutes(array $routes, $request, $includingMethod = true)
8181
{
82-
[$fallbacks, $routes] = (new Collection($routes))->partition(function ($route) {
83-
return $route->isFallback;
84-
});
82+
$fallbackRoute = null;
8583

86-
return $routes->merge($fallbacks)->first(
87-
fn (Route $route) => $route->matches($request, $includingMethod)
88-
);
84+
foreach ($routes as $route) {
85+
if ($route->matches($request, $includingMethod)) {
86+
if ($route->isFallback && $fallbackRoute === null) {
87+
$fallbackRoute = $route;
88+
89+
continue;
90+
}
91+
92+
return $route;
93+
}
94+
}
95+
96+
return $fallbackRoute;
8997
}
9098

9199
/**

0 commit comments

Comments
 (0)