1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 11:14:03 +00:00

Normalize the original storage path in tenantScopedPath too

Same as $configuredPath, $originalStoragePath isn't guaranteed to use OS separators either. On Windows, a storage path like 'C:/app/storage' would make the str_starts_with check return false even if true was expected.

Note that configuring the storage path to use '/' on Windows sounds very unlikely -- implementing this primarily for symmetry with $configuredPath.
This commit is contained in:
lukinovec 2026-08-26 17:40:14 +02:00
parent 857c6fc233
commit 3ee5a8e426

View file

@ -238,14 +238,15 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
*/
protected function tenantScopedPath(string $configuredPath, string $suffix): string
{
// Normalize the path to use the separator of the current OS.
// Normalize the paths to use the separator of the current OS.
$configuredPath = str_replace('/', DIRECTORY_SEPARATOR, $configuredPath);
$storagePath = str_replace('/', DIRECTORY_SEPARATOR, $this->originalStoragePath);
if (str_starts_with($configuredPath, $this->originalStoragePath . DIRECTORY_SEPARATOR)) {
if (str_starts_with($configuredPath, $storagePath . DIRECTORY_SEPARATOR)) {
// Swap the central storage path prefix for the tenant's.
// For example, storage_path('framework/cache/data') becomes storage_path('tenant1/framework/cache/data').
return str($configuredPath)
->after($this->originalStoragePath . DIRECTORY_SEPARATOR)
->after($storagePath . DIRECTORY_SEPARATOR)
->prepend($this->tenantStoragePath($suffix) . DIRECTORY_SEPARATOR)
->toString();
}