mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 12:44:04 +00:00
Resolver refactor, path identification improvements (#41)
* resolver refactor * Fix code style (php-cs-fixer) * make tenant column used in PathTenantResolver configurable, fix phpstan errors, minor improvements * support binding route fields, write tests for customizable tenant columns * Invalidate cache for all possible columns in path resolver * implement proper cache separation logic for different columns used by PathTenantResolver * improve return type --------- Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
parent
dc430666ba
commit
0c11f29c19
17 changed files with 370 additions and 88 deletions
|
|
@ -56,21 +56,22 @@ class DomainTenantResolver extends Contracts\CachedTenantResolver
|
|||
}
|
||||
}
|
||||
|
||||
public function getArgsForTenant(Tenant $tenant): array
|
||||
public function getPossibleCacheKeys(Tenant&Model $tenant): array
|
||||
{
|
||||
if ($tenant instanceof SingleDomainTenant) {
|
||||
/** @var SingleDomainTenant&Model $tenant */
|
||||
return [
|
||||
[$tenant->getOriginal('domain')], // Previous domain
|
||||
[$tenant->domain], // Current domain
|
||||
];
|
||||
$domains = array_filter([
|
||||
$tenant->getOriginal('domain'), // Previous domain
|
||||
$tenant->domain, // Current domain
|
||||
]);
|
||||
} else {
|
||||
/** @var Tenant&Model $tenant */
|
||||
$tenant->unsetRelation('domains');
|
||||
|
||||
$domains = $tenant->domains->map(function (Domain&Model $domain) {
|
||||
return $domain->domain;
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/** @var Tenant&Model $tenant */
|
||||
$tenant->unsetRelation('domains');
|
||||
|
||||
return $tenant->domains->map(function (Domain&Model $domain) {
|
||||
return [$domain->domain];
|
||||
})->toArray();
|
||||
return array_map(fn (string $domain) => $this->formatCacheKey($domain), $domains);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue