mirror of
https://github.com/archtechx/tenancy.git
synced 2026-09-20 12:34:03 +00:00
Make scopeSessions() respect the original configured session.files path instead of hardcoding /framework/sessions
Also rename tenantCachePath to tenantScopedPath since it's now used both for scoping cache and session paths. Note that the $originalPath local variable -- added that to avoid PHPStan errors.
This commit is contained in:
parent
efb417dada
commit
8c8bd6e88e
2 changed files with 15 additions and 8 deletions
|
|
@ -16,6 +16,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
public array $originalDisks = [];
|
public array $originalDisks = [];
|
||||||
protected array $originalCachePaths = [];
|
protected array $originalCachePaths = [];
|
||||||
protected array $originalCacheLockPaths = [];
|
protected array $originalCacheLockPaths = [];
|
||||||
|
protected string|null $originalSessionPath = null;
|
||||||
public string|null $originalAssetUrl;
|
public string|null $originalAssetUrl;
|
||||||
public string $originalStoragePath;
|
public string $originalStoragePath;
|
||||||
|
|
||||||
|
|
@ -213,7 +214,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
$this->originalCacheLockPaths[$name] = $store['lock_path'] ?? null;
|
$this->originalCacheLockPaths[$name] = $store['lock_path'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $suffix ? $this->tenantCachePath($this->originalCachePaths[$name], $suffix) : $this->originalCachePaths[$name];
|
$path = $suffix ? $this->tenantScopedPath($this->originalCachePaths[$name], $suffix) : $this->originalCachePaths[$name];
|
||||||
|
|
||||||
// Unlike path, lock_path is optional -- if it's not set, FileStore::lock() falls back to path
|
// Unlike path, lock_path is optional -- if it's not set, FileStore::lock() falls back to path
|
||||||
// itself (see `$this->lockDirectory ?? $this->directory` in FileStore). Leave it null here rather
|
// itself (see `$this->lockDirectory ?? $this->directory` in FileStore). Leave it null here rather
|
||||||
|
|
@ -221,7 +222,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
// doesn't end up with one.
|
// doesn't end up with one.
|
||||||
$lockPath = $this->originalCacheLockPaths[$name];
|
$lockPath = $this->originalCacheLockPaths[$name];
|
||||||
if ($suffix && $lockPath !== null) {
|
if ($suffix && $lockPath !== null) {
|
||||||
$lockPath = $this->tenantCachePath($lockPath, $suffix);
|
$lockPath = $this->tenantScopedPath($lockPath, $suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app['config']["cache.stores.{$name}.path"] = $path;
|
$this->app['config']["cache.stores.{$name}.path"] = $path;
|
||||||
|
|
@ -234,8 +235,11 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Scope a configured cache path (path or lock_path) to the tenant identified by $suffix. */
|
/**
|
||||||
protected function tenantCachePath(string $configuredPath, string $suffix): string
|
* Scope a configured path (a cache store's path or lock_path, or the session path)
|
||||||
|
* to the tenant identified by $suffix.
|
||||||
|
*/
|
||||||
|
protected function tenantScopedPath(string $configuredPath, string $suffix): string
|
||||||
{
|
{
|
||||||
if (str_starts_with($configuredPath, $this->originalStoragePath . '/')) {
|
if (str_starts_with($configuredPath, $this->originalStoragePath . '/')) {
|
||||||
// Swap the central storage path prefix for the tenant's.
|
// Swap the central storage path prefix for the tenant's.
|
||||||
|
|
@ -256,12 +260,15 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$originalPath = $this->originalSessionPath ?? $this->app['config']['session.files'];
|
||||||
|
$this->originalSessionPath = $originalPath;
|
||||||
|
|
||||||
$path = $suffix
|
$path = $suffix
|
||||||
? $this->tenantStoragePath($suffix) . '/framework/sessions'
|
? $this->tenantScopedPath($originalPath, $suffix)
|
||||||
: $this->originalStoragePath . '/framework/sessions';
|
: $originalPath;
|
||||||
|
|
||||||
if (! is_dir($path)) {
|
if (! is_dir($path)) {
|
||||||
// Create tenant framework/sessions directory if it does not exist.
|
// Create tenant session directory if it does not exist.
|
||||||
// We ignore errors due to TOCTOU race conditions, instead we check for success below.
|
// We ignore errors due to TOCTOU race conditions, instead we check for success below.
|
||||||
@mkdir($path, 0750, true);
|
@mkdir($path, 0750, true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -572,7 +572,7 @@ test('a file cache store without a configured lock_path defaults to using its sc
|
||||||
});
|
});
|
||||||
|
|
||||||
test('a cache store using a path not based on storage_path() has the tenant suffix appended', function () {
|
test('a cache store using a path not based on storage_path() has the tenant suffix appended', function () {
|
||||||
// tenantCachePath() has no central storage path prefix to swap for the tenant's here,
|
// tenantScopedPath() has no central storage path prefix to swap for the tenant's here,
|
||||||
// so it appends the tenant suffix to $path instead.
|
// so it appends the tenant suffix to $path instead.
|
||||||
$path = '/tmp/tenancy-cache-test';
|
$path = '/tmp/tenancy-cache-test';
|
||||||
File::deleteDirectory($path);
|
File::deleteDirectory($path);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue