1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-08-06 04:54:04 +00:00

Refactor FS bootstrapper

scopeCache() didn't feel right since it 1) stored thee original paths, 2) actually scoped things. Separate the concerns so that scopeCache() just does that -- scopes cache.
This commit is contained in:
lukinovec 2026-07-31 14:00:36 +02:00
parent 483a3ec802
commit 958fc8e06d

View file

@ -46,6 +46,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
$this->storagePath($suffix);
$this->assetHelper($suffix);
$this->forgetDisks();
$this->storeOriginalCachePaths();
$this->scopeCache($suffix);
$this->scopeSessions($suffix);
@ -200,13 +201,10 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
}
}
public function scopeCache(string|false $suffix): void
/** Returns the names of the file-driver stores listed in tenancy.cache.stores. */
protected function fileCacheStores(): array
{
if (! $this->app['config']['tenancy.filesystem.scope_cache']) {
return;
}
$stores = array_filter($this->app['config']['tenancy.cache.stores'], function ($name) {
return array_filter($this->app['config']['tenancy.cache.stores'], function ($name) {
$store = $this->app['config']["cache.stores.{$name}"];
if ($store === null) {
@ -215,15 +213,36 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
return $store['driver'] === 'file';
});
}
foreach ($stores as $name) {
// Store the original configured cache paths, unless they're already stored --
// scopeCache() is also called in revert(), by which point the originals were
// already captured in bootstrap().
/**
* Store the original configured cache paths, so that they can be properly scoped
* to a tenant and restored back to the central context when tenancy ends.
*/
protected function storeOriginalCachePaths(): void
{
if (! $this->app['config']['tenancy.filesystem.scope_cache']) {
return;
}
foreach ($this->fileCacheStores() as $name) {
$this->originalCachePaths[$name] ??= [
'path' => $this->app['config']["cache.stores.{$name}.path"],
'lock_path' => $this->app['config']["cache.stores.{$name}.lock_path"],
];
}
}
protected function scopeCache(string|false $suffix): void
{
if (! $this->app['config']['tenancy.filesystem.scope_cache']) {
return;
}
foreach ($this->fileCacheStores() as $name) {
if (! isset($this->originalCachePaths[$name])) {
continue;
}
$path = $this->scopeCachePath($this->originalCachePaths[$name]['path'], $suffix);
$lockPath = $this->originalCachePaths[$name]['lock_path'];