1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 02:54:03 +00:00
This commit is contained in:
Samuel Štancl 2019-11-08 16:41:56 +01:00
parent 2b00665247
commit 3d45e835e0
3 changed files with 51 additions and 0 deletions

View file

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Traits;
use Symfony\Component\Console\Input\InputOption;
trait HasATenantsOption
{
protected function getOptions()
{
return array_merge([
['tenant', null, InputOption::VALUE_REQUIRED, '', null],
], parent::getOptions());
}
protected function getTenants(): array
{
return tenancy()->all($this->option('tenants'))->all();
}
}

View file

@ -14,4 +14,9 @@ trait HasATenantsOption
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null], ['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null],
], parent::getOptions()); ], parent::getOptions());
} }
protected function getTenants(): array
{
return tenancy()->all($this->option('tenants'))->all();
}
} }

View file

@ -0,0 +1,24 @@
<?php
use Stancl\Tenancy\Tenant;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
trait TenantAwareCommand
{
protected function execute(InputInterface $input, OutputInterface $output): void
{
array_map(function (Tenant $tenant) {
$tenant->run(function () {
$this->laravel->call([$this, 'handle']);
});
}, $this->getTenants());
}
/**
* Get an array of tenants for which the command should be executed.
*
* @return Tenant[]
*/
abstract protected function getTenants(): array;
}