mirror of
https://github.com/archtechx/tenancy.git
synced 2026-09-20 14:14:03 +00:00
Correct and simplify tenantScopedPath()
Instead of using the normalized path in the returned result, use the actual configured path (keeping its original separators). The separator normalization got removed completely. Accepting either separator at the prefix boundary (`str($configuredPath)->startsWith([$centralPath . '/', $centralPath . '\\'])`) covers what the normalization was there for, e.g. a path configured as `storage_path() . '/framework/foo_sessions'` while `storage_path()` joins the segments with `\` on Windows. Note that this does not cover the case where the configured path uses different separators than the original (central) path. For example, `C:\app\storage\framework\cache` while `storage_path()` is `C:/app/storage`. A case like this would need a `replace()` in the check.
This commit is contained in:
parent
10de159b88
commit
127945190e
1 changed files with 6 additions and 8 deletions
|
|
@ -238,22 +238,20 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
*/
|
*/
|
||||||
protected function tenantScopedPath(string $configuredPath, string $suffix): string
|
protected function tenantScopedPath(string $configuredPath, string $suffix): string
|
||||||
{
|
{
|
||||||
// Normalize the paths to use the separator of the current OS.
|
$centralPath = rtrim($this->originalStoragePath, '/\\');
|
||||||
$configuredPath = str_replace('/', DIRECTORY_SEPARATOR, $configuredPath);
|
|
||||||
$storagePath = str_replace('/', DIRECTORY_SEPARATOR, $this->originalStoragePath);
|
|
||||||
|
|
||||||
if (str_starts_with($configuredPath, $storagePath . DIRECTORY_SEPARATOR)) {
|
if (str($configuredPath)->startsWith([$centralPath . '/', $centralPath . '\\'])) {
|
||||||
// Swap the central storage path prefix for the tenant's.
|
// Swap the central storage path prefix for the tenant's, keeping the configured separators.
|
||||||
// For example, storage_path('framework/cache/data') becomes storage_path('tenant1/framework/cache/data').
|
// For example, storage_path('framework/cache/data') becomes storage_path('tenant1/framework/cache/data').
|
||||||
return str($configuredPath)
|
return str($configuredPath)
|
||||||
->after($storagePath . DIRECTORY_SEPARATOR)
|
->after($centralPath)
|
||||||
->prepend($this->tenantStoragePath($suffix) . DIRECTORY_SEPARATOR)
|
->prepend($this->tenantStoragePath($suffix))
|
||||||
->toString();
|
->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise $configuredPath isn't necessarily storage_path()-based, so just append the
|
// Otherwise $configuredPath isn't necessarily storage_path()-based, so just append the
|
||||||
// suffix as a subdirectory, e.g. '/var/cache/foo' becomes '/var/cache/foo/tenant1'.
|
// suffix as a subdirectory, e.g. '/var/cache/foo' becomes '/var/cache/foo/tenant1'.
|
||||||
return rtrim($configuredPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $suffix;
|
return rtrim($configuredPath, '/\\') . DIRECTORY_SEPARATOR . $suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSessions(string|false $suffix): void
|
public function scopeSessions(string|false $suffix): void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue