1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 18:14:04 +00:00

Add optionNotPassedValue property

This commit is contained in:
lukinovec 2022-10-05 10:18:56 +02:00
parent ed4632142b
commit e3e85a0e88

View file

@ -13,25 +13,29 @@ use Symfony\Component\Console\Input\InputOption;
*/ */
trait HasTenantOptions trait HasTenantOptions
{ {
/** Value indicating an option wasn't passed */
protected $optionNotPassedValue = 'not passed';
protected function getOptions() protected function getOptions()
{ {
return array_merge([ return array_merge([
['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, '', null], ['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, '', null],
['with-pending', null, InputOption::VALUE_OPTIONAL, 'include pending tenants in query', false], ['with-pending', null, InputOption::VALUE_OPTIONAL, 'include pending tenants in query', $this->optionNotPassedValue],
], parent::getOptions()); ], parent::getOptions());
} }
protected function getWithPendingOption(): bool protected function getWithPendingOption(): bool
{ {
$optionPassedWithoutArgument = is_null($this->option('with-pending')); $optionPassedWithoutArgument = is_null($this->option('with-pending'));
$optionPassedWithArgument = is_string($this->option('with-pending')); $optionPassedWithArgument = $this->option('with-pending') !== $this->optionNotPassedValue;
// E.g. tenants:run --with-pending // E.g. 'tenants:run --with-pending'
if ($optionPassedWithoutArgument) { if ($optionPassedWithoutArgument) {
return true; return true;
} }
// E.g. tenants:run --with-pending=false // E.g. 'tenants:run --with-pending=false'
// If the passed value can't get converted to a bool (e.g. --with-pending=foo), default to false
if ($optionPassedWithArgument) { if ($optionPassedWithArgument) {
return filter_var($this->option('with-pending'), FILTER_VALIDATE_BOOLEAN); return filter_var($this->option('with-pending'), FILTER_VALIDATE_BOOLEAN);
} }