Created
July 11, 2023 15:36
-
-
Save carestad/6f7793e9e64e855bacf2f14e43dc6c30 to your computer and use it in GitHub Desktop.
Laravel trait with method to only return options defined in command signature, e.g. exclude Laravel/Symfony's default ones like --help and etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands\Traits; | |
use Illuminate\Support\Arr; | |
trait CommandTrait | |
{ | |
/** | |
* Get the self-defined options for the command, e.g. exclude Laravel/Symfony's default options | |
*/ | |
protected function definedOptions(): array | |
{ | |
// Get application default options, so we can exclude them from results | |
$defaultOptions = $this->getApplication()->getDefinition()->getOptions(); | |
return Arr::except($this->options(), array_keys($defaultOptions)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment