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

Merge branch '3.x' into patch-1

This commit is contained in:
Vincent GS 2022-05-13 11:47:37 -05:00 committed by GitHub
commit 658043ecd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 185 additions and 95 deletions

View file

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
@ -54,22 +53,22 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
}
// Storage facade
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
/** @var FilesystemAdapter $filesystemDisk */
$filesystemDisk = Storage::disk($disk);
$this->originalPaths['disks'][$disk] = $filesystemDisk->getAdapter()->getPathPrefix();
$subject = $this->app['config']["tenancy.filesystem.root_override.{$disk}"] ?? '';
Storage::forgetDisk($this->app['config']['tenancy.filesystem.disks']);
if ($root = str_replace(
'%storage_path%',
storage_path(),
$subject
)) {
$root = str_replace('%tenant%', $suffix, $root);
$filesystemDisk->getAdapter()->setPathPrefix($finalPrefix = $root);
} else {
$root = $this->app['config']["filesystems.disks.{$disk}.root"];
$filesystemDisk->getAdapter()->setPathPrefix($finalPrefix = $root . "/{$suffix}");
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
$originalRoot = $this->app['config']["filesystems.disks.{$disk}.root"];
$this->originalPaths['disks'][$disk] = $originalRoot;
$finalPrefix = str_replace(
['%storage_path%', '%tenant%'],
[storage_path(), $tenant->getTenantKey()],
$this->app['config']["tenancy.filesystem.root_override.{$disk}"] ?? '',
);
if (! $finalPrefix) {
$finalPrefix = $originalRoot
? rtrim($originalRoot, '/') . '/'. $suffix
: $suffix;
}
$this->app['config']["filesystems.disks.{$disk}.root"] = $finalPrefix;
@ -86,14 +85,9 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
// Storage facade
Storage::forgetDisk($this->app['config']['tenancy.filesystem.disks']);
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
/** @var FilesystemAdapter $filesystemDisk */
$filesystemDisk = Storage::disk($disk);
$root = $this->originalPaths['disks'][$disk];
$filesystemDisk->getAdapter()->setPathPrefix($root);
$this->app['config']["filesystems.disks.{$disk}.root"] = $root;
$this->app['config']["filesystems.disks.{$disk}.root"] = $this->originalPaths['disks'][$disk];
}
}
}