| 1 | <?php |
||
| 15 | abstract class AbstractCommand extends SymfonyCommand |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * The command description. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $description = ''; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The Input implementation. |
||
| 26 | * |
||
| 27 | * @var InputInterface |
||
| 28 | */ |
||
| 29 | protected $input; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The Output implementation. |
||
| 33 | * |
||
| 34 | * @var OutputInterface |
||
| 35 | */ |
||
| 36 | protected $output; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The command signature. |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $signature = ''; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | 1 | final public function run(InputInterface $input, OutputInterface $output) |
|
| 49 | { |
||
| 50 | 1 | $this->input = $input; |
|
| 51 | 1 | $this->output = $output; |
|
| 52 | |||
| 53 | 1 | return parent::run($input, $output); |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | 2 | protected function configure() |
|
| 60 | { |
||
| 61 | 2 | $signature = (new SignatureParser())->parse($this->signature); |
|
| 62 | |||
| 63 | 2 | $this->setName($signature['name']); |
|
| 64 | 2 | $this->setDescription($this->description); |
|
| 65 | |||
| 66 | 2 | foreach ($signature['arguments'] as $argument) { |
|
| 67 | 2 | $this->addArgument( |
|
| 68 | 2 | $argument['name'], |
|
| 69 | 2 | $argument['type'], |
|
| 70 | 2 | $argument['description'], |
|
| 71 | 2 | $argument['default'] |
|
| 72 | ); |
||
| 73 | } |
||
| 74 | |||
| 75 | 2 | foreach ($signature['options'] as $option) { |
|
| 76 | 2 | $this->addOption($option['name'], null, $option['type'], $option['description'], $option['default']); |
|
| 77 | } |
||
| 78 | 2 | } |
|
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | 1 | final protected function execute(InputInterface $input, OutputInterface $output) |
|
| 84 | { |
||
| 85 | 1 | return $this->handle(); |
|
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * The command handler. |
||
| 90 | * |
||
| 91 | * @return int Exit code. |
||
| 92 | */ |
||
| 93 | abstract protected function handle(); |
||
| 94 | } |