1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:14:04 +00:00

Format code in Link command, make writing more concise

This commit is contained in:
lukinovec 2022-07-28 10:33:08 +02:00
parent 428bce896a
commit 4772f30e27

View file

@ -28,7 +28,7 @@ class Link extends Command
* *
* @var string * @var string
*/ */
protected $description = 'Create the symbolic links configured for the tenancy applications'; protected $description = 'Create symbolic links for tenants.';
/** /**
* Execute the console command. * Execute the console command.
@ -76,15 +76,15 @@ class Link extends Command
} }
/** /**
* Get the symbolic links that are configured for the application. * Create symbolic links using the tenancy.filesystem config.
* *
* @return array * @return array
*/ */
protected function links() protected function links()
{ {
$disk_urls = config('tenancy.filesystem.url_override'); $diskUrls = config('tenancy.filesystem.url_override');
$disks = config('tenancy.filesystem.root_override'); $disks = config('tenancy.filesystem.root_override');
$suffix_base = config('tenancy.filesystem.suffix_base'); $suffixBase = config('tenancy.filesystem.suffix_base');
$tenants = $this->option('remove') && filled($this->option('tenants')) $tenants = $this->option('remove') && filled($this->option('tenants'))
? collect($this->option('tenants')) ? collect($this->option('tenants'))
@ -92,35 +92,32 @@ class Link extends Command
return $tenant->getTenantKey(); return $tenant->getTenantKey();
}); });
return $tenants return $tenants->map(function ($tenantKey) use ($suffixBase, $diskUrls, $disks) {
->map(function ($tenant_key) use ($suffix_base, $disk_urls, $disks) { $symLinks = [];
$map = [];
foreach ($disk_urls as $disk => $public_path) { foreach ($diskUrls as $disk => $publicPath) {
$storage_path = str_replace('%storage_path%', $suffix_base . $tenant_key, $disks[$disk]); $storagePath = str_replace('%storage_path%', $suffixBase . $tenantKey, $disks[$disk]);
$storage_path = storage_path($storage_path); $storagePath = storage_path($storagePath);
$public_path = str_replace('%tenant_id%', $tenant_key, $public_path); $publicPath = str_replace('%tenant_id%', $tenantKey, $publicPath);
$public_path = public_path($public_path); $publicPath = public_path($publicPath);
// make sure storage path exist before we create symlink // Make sure the storage path exists before we create a symlink
if (! is_dir($storage_path)) { if (! is_dir($storagePath)) {
mkdir($storage_path, 0777, true); mkdir($storagePath, 0777, true);
}
$map[] = [$public_path => $storage_path];
} }
return $map; $symLinks[] = [$publicPath => $storagePath];
})->flatten(1) }
->mapWithKeys(function ($item) {
return $item; return $symLinks;
}) })->flatten(1)
->all(); ->mapWithKeys(fn ($item) => $item)
->all();
} }
/** /**
* Determine if the provided path is a symlink that can be removed. * Determine if the provided path is a removable symlink.
*/ */
protected function isRemovableSymlink(string $link, bool $force): bool protected function isRemovableSymlink(string $link, bool $force): bool
{ {