Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static variable for MiddlewareUniversalName. #581

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Features/UniversalRoutes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare (strict_types = 1);
stancl marked this conversation as resolved.
Show resolved Hide resolved

namespace Stancl\Tenancy\Features;

Expand All @@ -13,6 +13,8 @@

class UniversalRoutes implements Feature
{
public static $middlewareUniversalName = 'universal';
stancl marked this conversation as resolved.
Show resolved Hide resolved

public static $identificationMiddlewares = [
Middleware\InitializeTenancyByDomain::class,
Middleware\InitializeTenancyBySubdomain::class,
Expand All @@ -22,7 +24,7 @@ public function bootstrap(Tenancy $tenancy): void
{
foreach (static::$identificationMiddlewares as $middleware) {
$middleware::$onFail = function ($exception, $request, $next) {
if (static::routeHasMiddleware($request->route(), 'universal')) {
if (static::routeHasMiddleware($request->route(), static::$middlewareUniversalName)) {
return $next($request);
}

Expand All @@ -41,7 +43,7 @@ public static function routeHasMiddleware(Route $route, $middleware): bool
// groups have the searhced middleware group inside them
$middlewareGroups = Router::getMiddlewareGroups();
foreach ($route->gatherMiddleware() as $inner) {
if (! $inner instanceof Closure && isset($middlewareGroups[$inner]) && in_array($middleware, $middlewareGroups[$inner], true)) {
if (!$inner instanceof Closure && isset($middlewareGroups[$inner]) && in_array($middleware, $middlewareGroups[$inner], true)) {
stancl marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
}
Expand Down