1
0
cms11/app/Console/Commands/Bundle/Traits/SelectsDisks.php

62 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands\Bundle\Traits;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Storage;
trait SelectsDisks
{
protected Filesystem $sourceDisk;
protected Filesystem $targetDisk;
/**
* Select the disk we will be working on
*/
private function selectDisk(?bool $source = true, ?bool $target = false): self
{
if ($source) {
$this->selectSourceDisk();
}
if ($target) {
$this->selectTargetDisk();
}
return $this;
}
private function selectSourceDisk()
{
$sourceDisk = $this->option('source-disk') ?? env('CONTENT_DISK');
$this->sourceDisk = Storage::disk($sourceDisk);
$this->line(
sprintf(
'Using <info>%s</info> as source disk',
$sourceDisk
)
);
return $this;
}
private function selectTargetDisk()
{
$targetDisk = $this->option('target-disk') ?? env('DIST_DISK');
$this->targetDisk = Storage::disk($targetDisk);
$this->line(
sprintf(
'Using <info>%s</info> as target disk',
$targetDisk
)
);
return $this;
}
}