From cabf66f95379317331a73742e39decdafb85227c Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 28 Jan 2020 07:59:48 +0800 Subject: [PATCH 1/2] [6.x] Split specifyParameter() to external trait. While building orchestra/canvas, I found out that while it would be nice to use Illuminate\Console\Command the requirements to have Laravel (or at least the Container) configure make it slightly harder to build PHP CLI code based on symfony console with a little Laravel flavour. Signed-off-by: Mior Muhammad Zaki --- src/Illuminate/Console/Command.php | 48 +--------------- .../Console/Concerns/HasParameters.php | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 47 deletions(-) create mode 100644 src/Illuminate/Console/Concerns/HasParameters.php diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index 82e88165e423..f65357bd7c26 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -18,6 +18,7 @@ class Command extends SymfonyCommand { use Concerns\CallsCommands, + Concerns\HasParameters, Macroable; /** @@ -144,33 +145,6 @@ protected function configureUsingFluentDefinition() $this->getDefinition()->addOptions($options); } - /** - * Specify the arguments and options on the command. - * - * @return void - */ - protected function specifyParameters() - { - // We will loop through all of the arguments and options for the command and - // set them all on the base command instance. This specifies what can get - // passed into these commands as "parameters" to control the execution. - foreach ($this->getArguments() as $arguments) { - if ($arguments instanceof InputArgument) { - $this->getDefinition()->addArgument($arguments); - } else { - call_user_func_array([$this, 'addArgument'], $arguments); - } - } - - foreach ($this->getOptions() as $options) { - if ($options instanceof InputOption) { - $this->getDefinition()->addOption($options); - } else { - call_user_func_array([$this, 'addOption'], $options); - } - } - } - /** * Run the console command. * @@ -581,26 +555,6 @@ public function setHidden($hidden) return $this; } - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return []; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return []; - } - /** * Get the output implementation. * diff --git a/src/Illuminate/Console/Concerns/HasParameters.php b/src/Illuminate/Console/Concerns/HasParameters.php new file mode 100644 index 000000000000..3f6f9c7642cf --- /dev/null +++ b/src/Illuminate/Console/Concerns/HasParameters.php @@ -0,0 +1,56 @@ +getArguments() as $arguments) { + if ($arguments instanceof InputArgument) { + $this->getDefinition()->addArgument($arguments); + } else { + call_user_func_array([$this, 'addArgument'], $arguments); + } + } + + foreach ($this->getOptions() as $options) { + if ($options instanceof InputOption) { + $this->getDefinition()->addOption($options); + } else { + call_user_func_array([$this, 'addOption'], $options); + } + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return []; + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return []; + } +} From 89687db2fb02400cf3ad9c5941d3bc659ece6f6b Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 28 Jan 2020 08:39:08 +0800 Subject: [PATCH 2/2] Remove unused import --- src/Illuminate/Console/Command.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index f65357bd7c26..5de258fa6427 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -8,9 +8,7 @@ use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Helper\Table; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\Question;