HasParameters.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Command\Concerns;
  12. use Symfony\Component\Console\Input\InputArgument;
  13. use Symfony\Component\Console\Input\InputOption;
  14. trait HasParameters
  15. {
  16. /**
  17. * Specify the arguments and options on the command.
  18. */
  19. protected function specifyParameters()
  20. {
  21. // We will loop through all of the arguments and options for the command and
  22. // set them all on the base command instance. This specifies what can get
  23. // passed into these commands as "parameters" to control the execution.
  24. foreach ($this->getArguments() as $arguments) {
  25. if ($arguments instanceof InputArgument) {
  26. $this->getDefinition()->addArgument($arguments);
  27. } else {
  28. $this->addArgument(...$arguments);
  29. }
  30. }
  31. foreach ($this->getOptions() as $options) {
  32. if ($options instanceof InputOption) {
  33. $this->getDefinition()->addOption($options);
  34. } else {
  35. $this->addOption(...$options);
  36. }
  37. }
  38. }
  39. /**
  40. * Get the console command arguments.
  41. *
  42. * @return array
  43. */
  44. protected function getArguments()
  45. {
  46. return [];
  47. }
  48. /**
  49. * Get the console command options.
  50. *
  51. * @return array
  52. */
  53. protected function getOptions()
  54. {
  55. return [];
  56. }
  57. }