mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 20:34:03 +00:00
Update FilesystemTenancyBootstrapper
This commit is contained in:
parent
14c87ec3e6
commit
5002b308d8
1 changed files with 25 additions and 23 deletions
|
|
@ -4,11 +4,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Bootstrappers;
|
namespace Stancl\Tenancy\Bootstrappers;
|
||||||
|
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use League\Flysystem\Adapter\Local as LocalAdapter;
|
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
|
|
||||||
class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
|
|
@ -57,9 +56,9 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
Storage::forgetDisk($this->app['config']['tenancy.filesystem.disks']);
|
Storage::forgetDisk($this->app['config']['tenancy.filesystem.disks']);
|
||||||
|
|
||||||
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
||||||
// todo@v4 \League\Flysystem\PathPrefixer is making this a lot more painful in flysystem v2
|
/** @var string|null $originalRoot */
|
||||||
|
$originalRoot = $this->getDiskConfig($disk)['root'] ?? null;
|
||||||
|
|
||||||
$originalRoot = $this->app['config']["filesystems.disks.{$disk}.root"];
|
|
||||||
$this->originalPaths['disks']['path'][$disk] = $originalRoot;
|
$this->originalPaths['disks']['path'][$disk] = $originalRoot;
|
||||||
|
|
||||||
$finalPrefix = str_replace(
|
$finalPrefix = str_replace(
|
||||||
|
|
@ -74,21 +73,18 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
: $suffix;
|
: $suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app['config']["filesystems.disks.{$disk}.root"] = $finalPrefix;
|
$this->updateDiskConfig($disk, 'root', $finalPrefix);
|
||||||
|
|
||||||
// Storage Url
|
// Storage Url
|
||||||
if ($filesystemDisk->getAdapter() instanceof LocalAdapter) {
|
if ($this->getDiskConfig($disk)['driver'] === 'local') {
|
||||||
$config = $filesystemDisk->getDriver()->getConfig();
|
$this->originalPaths['disks']['url'][$disk] = $this->getDiskConfig($disk)['url'] ?? null;
|
||||||
$this->originalPaths['disks']['url'][$disk] = $config->has('url')
|
|
||||||
? $config->get('url')
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if ($url = str_replace(
|
if ($url = str_replace(
|
||||||
'%tenant_id%',
|
'%tenant_id%',
|
||||||
$tenant->getTenantKey(),
|
$tenant->getTenantKey(),
|
||||||
$this->app['config']["tenancy.filesystem.url_override.{$disk}"] ?? ''
|
$this->app['config']["tenancy.filesystem.url_override.{$disk}"] ?? ''
|
||||||
)) {
|
)) {
|
||||||
$config->set('url', url($url));
|
$this->updateDiskConfig($disk, 'url', url($url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,19 +102,25 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
// Storage facade
|
// Storage facade
|
||||||
Storage::forgetDisk($this->app['config']['tenancy.filesystem.disks']);
|
Storage::forgetDisk($this->app['config']['tenancy.filesystem.disks']);
|
||||||
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
||||||
/** @var FilesystemAdapter $filesystemDisk */
|
$this->updateDiskConfig($disk, 'root', $this->originalPaths['disks']['path'][$disk]);
|
||||||
$filesystemDisk = Storage::disk($disk);
|
|
||||||
|
|
||||||
$root = $this->originalPaths['disks']['path'][$disk];
|
|
||||||
|
|
||||||
$filesystemDisk->getAdapter()->setPathPrefix($root);
|
|
||||||
$this->app['config']["filesystems.disks.{$disk}.root"] = $root;
|
|
||||||
|
|
||||||
// Storage Url
|
// Storage Url
|
||||||
if ($filesystemDisk->getAdapter() instanceof LocalAdapter && ! is_null($this->originalPaths['disks']['url'])) {
|
$url = $this->originalPaths['disks.url.' . $disk] ?? null;
|
||||||
$config = $filesystemDisk->getDriver()->getConfig();
|
|
||||||
$config->set('url', $this->originalPaths['disks']['url']);
|
if ($this->getDiskConfig($disk)['driver'] === 'local' && ! is_null($url)) {
|
||||||
|
$this->updateDiskConfig($disk, 'url', $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return array|null */
|
||||||
|
protected function getDiskConfig(string $diskName)
|
||||||
|
{
|
||||||
|
return $this->app['config']['filesystems.disks.' . $diskName] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateDiskConfig(string $diskName, string $updateProperty, $value)
|
||||||
|
{
|
||||||
|
$this->app['config']["filesystems.disks.$diskName.$updateProperty"] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue