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 | final public function run(InputInterface $input, OutputInterface $output) |
||
49 | { |
||
50 | $this->input = $input; |
||
51 | $this->output = $output; |
||
52 | |||
53 | return parent::run($input, $output); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | final protected function configure() |
||
60 | { |
||
61 | $signature = (new SignatureParser())->parse($this->signature); |
||
62 | |||
63 | $this->setName($signature['name']); |
||
64 | $this->setDescription($this->description); |
||
65 | |||
66 | foreach ($signature['arguments'] as $argument) { |
||
67 | $this->addArgument( |
||
68 | $argument['name'], |
||
69 | $argument['type'], |
||
70 | $argument['description'], |
||
71 | $argument['default'] |
||
72 | ); |
||
73 | } |
||
74 | |||
75 | foreach ($signature['options'] as $option) { |
||
76 | $this->addOption($option['name'], null, $option['type'], $option['description'], $option['default']); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | final protected function execute(InputInterface $input, OutputInterface $output) |
||
84 | { |
||
85 | return $this->handle(); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * The command handler. |
||
90 | * |
||
91 | * @return int Exit code. |
||
92 | */ |
||
93 | abstract protected function handle(); |
||
94 | } |