1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 01:44:04 +00:00
tenancy/src/Traits/TenantAwareCommand.php
Devon Mather cf339a5e82
Add return value to execute method (#333)
* Add command for test

* Write test to verify issue

* Make test pass
2020-03-21 02:05:17 +01:00

39 lines
925 B
PHP

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