1 | <?php |
||
20 | trait ConfiguratorTrait |
||
21 | { |
||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $config; |
||
26 | |||
27 | /** |
||
28 | * @param array $config |
||
29 | */ |
||
30 | public function setConfig(array $config) : void |
||
34 | |||
35 | /** |
||
36 | * @return array |
||
37 | */ |
||
38 | public function getConfig(): array |
||
42 | |||
43 | /** |
||
44 | * @param CommandInterface $command |
||
45 | */ |
||
46 | public function configure(CommandInterface $command) : void |
||
57 | |||
58 | abstract protected function doConfigure(CommandInterface $command); |
||
59 | |||
60 | public function accept(CommandInterface $command): bool |
||
64 | |||
65 | abstract protected function doAccept(CommandInterface $command): bool; |
||
66 | |||
67 | /** |
||
68 | * @param array $config |
||
69 | * @return InputArgument[] |
||
70 | */ |
||
71 | protected function createArguments(array $config) |
||
84 | |||
85 | /** |
||
86 | * @param CommandInterface $command |
||
87 | */ |
||
88 | private function configureArguments(CommandInterface $command) |
||
99 | |||
100 | /** |
||
101 | * @param CommandInterface $command |
||
102 | */ |
||
103 | private function configureOptions(CommandInterface $command) |
||
104 | { |
||
105 | if (!isset($this->getConfig()[Config::OPTIONS_KEY])) { |
||
106 | return; |
||
107 | } |
||
108 | |||
109 | foreach ($this->getConfig()[Config::OPTIONS_KEY] as $name => $option) { |
||
110 | $command->addOption( |
||
111 | $name, |
||
112 | isset($option[Config::SHORTCUT_KEY]) ? $option[Config::SHORTCUT_KEY] : null, |
||
113 | isset($option[Config::MODE_KEY]) ? $option[Config::MODE_KEY] : null, |
||
114 | isset($option[Config::DESCRIPTION_KEY]) ? $option[Config::DESCRIPTION_KEY] : '' |
||
115 | ); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | private function getScalarConfig() |
||
128 | |||
129 | private function configureScalarProperties(CommandInterface $command) |
||
135 | } |
||
136 | |||
137 |