mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 01:14:03 +00:00
wip
This commit is contained in:
parent
2b00665247
commit
3d45e835e0
3 changed files with 51 additions and 0 deletions
22
src/Traits/HasATenantOption.php
Normal file
22
src/Traits/HasATenantOption.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
src/Traits/TenantAwareCommand.php
Normal file
24
src/Traits/TenantAwareCommand.php
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue