Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
chore: Try to avoid Route:: all lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Mar 16, 2018
1 parent cade0f5 commit 39ad437
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Laravel/Middleware/Cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ protected function hasShouldRouteGroup($request): bool

$shouldClsssName = ShouldGroup::class;
$shouldAlias = collect(Route::getMiddleware())->flip()->get($shouldClsssName, $shouldClsssName);
$middlewareGroups = collect(Route::getMiddlewareGroups())->filter(function ($group) use ($shouldClsssName, $shouldAlias) {
return in_array($shouldAlias, $group) || in_array($shouldClsssName, $group);
})->keys();
$gatherMiddleware = collect(Route::getRoutes()->get())->first(function ($route) use ($request) {
return $route->uri() === $request->path();
})->gatherMiddleware();
Expand All @@ -106,6 +103,10 @@ protected function hasShouldRouteGroup($request): bool
return true;
}

$middlewareGroups = collect(Route::getMiddlewareGroups())->filter(function ($group) use ($shouldClsssName, $shouldAlias) {
return in_array($shouldAlias, $group) || in_array($shouldClsssName, $group);
})->keys();

return $middlewareGroups->filter(function ($value) use ($gatherMiddleware) {
return in_array($value, $gatherMiddleware);
})->isNotEmpty();
Expand Down

0 comments on commit 39ad437

Please sign in to comment.