1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 21:04:03 +00:00

Refactor early identification (#47)

* Make universal route logic part of tbe early ID trait

* Add requstHasTenant to prevent access MW, add todo@samuel

* Delete PathIdentificationManager, move the used methods appropriately

* Correct and refactor code related to the deleted PathIdentificationManager class

* Add docblock

* Fix code style (php-cs-fixer)

* refactor globalStackMiddleware()

* remove todos [ci skip]

* refactor routeMiddleware()

* revert bool assertions

* revert more changes

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
lukinovec 2024-04-22 11:30:58 +02:00 committed by GitHub
parent b70cd0e531
commit 4e51cdbacb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 95 additions and 256 deletions

View file

@ -10,7 +10,7 @@ use Illuminate\Routing\Router;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Stancl\Tenancy\Enums\RouteMode;
use Stancl\Tenancy\PathIdentificationManager;
use Stancl\Tenancy\Resolvers\PathTenantResolver;
/**
* The CloneRoutesAsTenant action clones
@ -75,7 +75,7 @@ class CloneRoutesAsTenant
protected function getRoutesToClone(): Collection
{
$tenantParameterName = PathIdentificationManager::getTenantParameterName();
$tenantParameterName = PathTenantResolver::tenantParameterName();
/**
* Clone all routes that:
@ -95,9 +95,10 @@ class CloneRoutesAsTenant
return false;
}
$routeHasPathIdentificationMiddleware = PathIdentificationManager::pathIdentificationOnRoute($route);
$pathIdentificationMiddlewareInGlobalStack = PathIdentificationManager::pathIdentificationInGlobalStack();
$pathIdentificationMiddleware = config('tenancy.identification.path_identification_middleware');
$routeHasPathIdentificationMiddleware = tenancy()->routeHasMiddleware($route, $pathIdentificationMiddleware);
$routeHasNonPathIdentificationMiddleware = tenancy()->routeHasIdentificationMiddleware($route) && ! $routeHasPathIdentificationMiddleware;
$pathIdentificationMiddlewareInGlobalStack = tenancy()->globalStackHasMiddleware($pathIdentificationMiddleware);
/**
* The route should get cloned if:
@ -163,7 +164,7 @@ class CloneRoutesAsTenant
->filter(fn (string $middleware) => ! in_array($middleware, ['universal', 'clone']))
->toArray();
$tenantRouteNamePrefix = PathIdentificationManager::getTenantRouteNamePrefix();
$tenantRouteNamePrefix = PathTenantResolver::tenantRouteNamePrefix();
// Make sure the route name has the tenant route name prefix
$newRouteNamePrefix = $route->getName()
@ -173,7 +174,7 @@ class CloneRoutesAsTenant
return $action
->put('as', $newRouteNamePrefix)
->put('middleware', $newRouteMiddleware)
->put('prefix', '/{' . PathIdentificationManager::getTenantParameterName() . '}/' . $route->getPrefix());
->put('prefix', '/{' . PathTenantResolver::tenantParameterName() . '}/' . $route->getPrefix());
})->toArray();
/** @var Route $newRoute */