Created
August 28, 2023 09:56
-
-
Save carestad/0986c44ed52fd5a48795b6aeb72820fd to your computer and use it in GitHub Desktop.
Laravel trait to get only self-defined options for command
This file contains 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