1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 14:14:04 +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

@ -6,7 +6,7 @@ namespace Stancl\Tenancy\Listeners;
use Illuminate\Routing\Events\RouteMatched;
use Stancl\Tenancy\Enums\RouteMode;
use Stancl\Tenancy\PathIdentificationManager;
use Stancl\Tenancy\Resolvers\PathTenantResolver;
/**
* Remove the tenant parameter from the matched route when path identification is used globally.
@ -26,12 +26,13 @@ class ForgetTenantParameter
{
public function handle(RouteMatched $event): void
{
$kernelPathIdentificationUsed = PathIdentificationManager::pathIdentificationInGlobalStack() && ! tenancy()->routeHasIdentificationMiddleware($event->route);
$pathIdentificationInGlobalStack = tenancy()->globalStackHasMiddleware(config('tenancy.identification.path_identification_middleware'));
$kernelPathIdentificationUsed = $pathIdentificationInGlobalStack && ! tenancy()->routeHasIdentificationMiddleware($event->route);
$routeMode = tenancy()->getRouteMode($event->route);
$routeModeIsTenantOrUniversal = $routeMode === RouteMode::TENANT || ($routeMode === RouteMode::UNIVERSAL && $event->route->hasParameter(PathIdentificationManager::getTenantParameterName()));
$routeModeIsTenantOrUniversal = $routeMode === RouteMode::TENANT || ($routeMode === RouteMode::UNIVERSAL && $event->route->hasParameter(PathTenantResolver::tenantParameterName()));
if ($kernelPathIdentificationUsed && $routeModeIsTenantOrUniversal) {
$event->route->forgetParameter(PathIdentificationManager::getTenantParameterName());
$event->route->forgetParameter(PathTenantResolver::tenantParameterName());
}
}
}