mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
Improve route cloning action (#8)
* Allow cloning routes when only kernel identification is used, explicitly enable specific cloning modes * Explicitly enable needed clone modes in tests, use "clone" instead of "reregister" * Fix code style (php-cs-fixer) * Use "cloning" instead of "re-registration" in UniversalRouteTest * Only clone routes using path identification * Revert clone mode changes * Fix code style (php-cs-fixer) * Update comment * Skip cloning 'stancl.tenancy.asset' by default * Decide which routes should get cloned in the filtering step, improve method organization * Return `RouteMode::UNIVERSAL` in getMiddlewareContext if route is universal * Give universal route the path ID MW so that it gets cloned * Fix code style (php-cs-fixer) * Simplify UsableWithEarlyIdentification code * Handle universal route mode in ForgetTenantParameter * Fix code style (php-cs-fixer) * Rename getMiddlewareContext to getRouteMode * Append '/' to the route prefix * Rename variable * Wrap part of condition in parentheses * Refresh name lookups after cloning routes * Test giving tenant flag to cloned routes * Add routeIsUniversal method * Correct ForgetTenantParameter condition * Improve tenant flag giving logic * Improve test name * Delete leftover testing code * Put part of condition into `()` * Improve CloneRoutesAsTenant code + comments * Extract route mode-related code into methods, refactor and improve code * Improve ForgetTenantParameter, test tenant parameter removing in universal routes * Fix code style (php-cs-fixer) * Fix test * Simplify adding tenant flag * Don't skip stancl.tenancy.asset route cloning * clean up comment * fix in_array() argument * Fix code style (php-cs-fixer) --------- Co-authored-by: PHP CS Fixer <phpcsfixer@example.com> Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
parent
4d4639450e
commit
f7d9f02fd4
9 changed files with 222 additions and 111 deletions
|
|
@ -19,17 +19,16 @@ use Stancl\Tenancy\PathIdentificationManager;
|
|||
* We remove the {tenant} parameter from the hydrated route when
|
||||
* 1) the InitializeTenancyByPath middleware is in the global stack, AND
|
||||
* 2) the matched route does not have identification middleware (so that {tenant} isn't forgotten when using route-level identification), AND
|
||||
* 3) the route has tenant middleware context (so that {tenant} doesn't get accidentally removed from central routes).
|
||||
* 3) the route isn't in the central context (so that {tenant} doesn't get accidentally removed from central routes).
|
||||
*/
|
||||
class ForgetTenantParameter
|
||||
{
|
||||
public function handle(RouteMatched $event): void
|
||||
{
|
||||
if (
|
||||
PathIdentificationManager::pathIdentificationInGlobalStack() &&
|
||||
! tenancy()->routeHasIdentificationMiddleware($event->route) &&
|
||||
tenancy()->getMiddlewareContext($event->route) === RouteMode::TENANT
|
||||
) {
|
||||
$kernelPathIdentificationUsed = PathIdentificationManager::pathIdentificationInGlobalStack() && ! tenancy()->routeHasIdentificationMiddleware($event->route);
|
||||
$routeModeIsTenant = tenancy()->getRouteMode($event->route) === RouteMode::TENANT;
|
||||
|
||||
if ($kernelPathIdentificationUsed && $routeModeIsTenant) {
|
||||
$event->route->forgetParameter(PathIdentificationManager::getTenantParameterName());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue