1 | <?php |
||
26 | class Configurator extends Runner |
||
27 | { |
||
28 | /** |
||
29 | * Force mode |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | private $force; |
||
34 | |||
35 | /** |
||
36 | * Extend existing config or create new one |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $mode; |
||
41 | |||
42 | /** |
||
43 | * Execute the configurator. |
||
44 | */ |
||
45 | 4 | public function run() |
|
60 | |||
61 | /** |
||
62 | * Force mode setter. |
||
63 | * |
||
64 | * @param bool $force |
||
65 | * @return \SebastianFeldmann\CaptainHook\Runner\Configurator |
||
66 | */ |
||
67 | 2 | public function force(bool $force) : Configurator |
|
72 | |||
73 | /** |
||
74 | * Set configuration mode. |
||
75 | * |
||
76 | * @param bool $extend |
||
77 | * @return \SebastianFeldmann\CaptainHook\Runner\Configurator |
||
78 | */ |
||
79 | 3 | public function extend(bool $extend) : Configurator |
|
84 | |||
85 | /** |
||
86 | * Return config to handle. |
||
87 | * |
||
88 | * @return \SebastianFeldmann\CaptainHook\Config |
||
89 | */ |
||
90 | 4 | public function getConfigToManipulate() : Config |
|
100 | |||
101 | /** |
||
102 | * Make sure force mode is set if config file exists. |
||
103 | * |
||
104 | * @throws \RuntimeException |
||
105 | */ |
||
106 | 2 | private function ensureForce() |
|
112 | |||
113 | /** |
||
114 | * Configure a hook. |
||
115 | * |
||
116 | * @param \SebastianFeldmann\CaptainHook\Config $config |
||
117 | * @param string $hook |
||
118 | */ |
||
119 | 5 | public function configureHook(Config $config, string $hook) |
|
141 | |||
142 | /** |
||
143 | * Setup a action config with user input. |
||
144 | * |
||
145 | * @return \SebastianFeldmann\CaptainHook\Config\Action |
||
146 | */ |
||
147 | 3 | public function getActionConfig() : Config\Action |
|
155 | |||
156 | /** |
||
157 | * Ask the user for any action options. |
||
158 | * |
||
159 | * @param string $type |
||
160 | * @return array |
||
161 | */ |
||
162 | 3 | public function getActionOptions(string $type) : array |
|
166 | |||
167 | /** |
||
168 | * Get the php action options. |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | 2 | protected function getPHPActionOptions() : array |
|
183 | |||
184 | /** |
||
185 | * Ask the user for a php action option. |
||
186 | * |
||
187 | * @return array |
||
188 | */ |
||
189 | 2 | protected function getPHPActionOption() : array |
|
190 | { |
||
191 | 2 | $result = []; |
|
192 | 2 | $answer = $this->io->askAndValidate( |
|
193 | 2 | ' <info>Specify options key and value</info> <comment>[key:value]</comment> ', |
|
194 | 2 | function ($value) { |
|
195 | if (count(explode(':', $value)) !== 2) { |
||
196 | throw new \Exception('Invalid option, use "key:value"'); |
||
197 | } |
||
198 | return $value; |
||
199 | 2 | }, |
|
200 | 2 | 3, |
|
201 | 2 | null |
|
202 | ); |
||
203 | 2 | if (null !== $answer) { |
|
204 | 2 | list($key, $value) = explode(':', $answer); |
|
205 | 2 | $result = [$key => $value]; |
|
206 | } |
||
207 | 2 | return $result; |
|
208 | } |
||
209 | |||
210 | /** |
||
211 | * Write config to project root. |
||
212 | * |
||
213 | * @param \SebastianFeldmann\CaptainHook\Config $config |
||
214 | */ |
||
215 | 3 | public function writeConfig(Config $config) |
|
221 | } |
||
222 |