1 | <?php |
||
20 | class ConfigureCommand extends AbstractCommand |
||
21 | { |
||
22 | /** |
||
23 | * Configures the current command. |
||
24 | */ |
||
25 | 4 | protected function configure() |
|
42 | |||
43 | /** |
||
44 | * @param InputInterface $input |
||
45 | * @param OutputInterface $output |
||
46 | * @return int |
||
47 | */ |
||
48 | 4 | protected function execute(InputInterface $input, OutputInterface $output) |
|
55 | |||
56 | /** |
||
57 | * @return int |
||
58 | */ |
||
59 | 4 | protected function process() |
|
70 | |||
71 | /** |
||
72 | * @return array<string,array<string,string|boolean>> |
||
73 | */ |
||
74 | 4 | private function getInputValues() |
|
125 | |||
126 | /** |
||
127 | * @param string $valueKey |
||
128 | * @param string $question |
||
129 | * @param boolean $hideAnswer |
||
130 | * @return string |
||
131 | */ |
||
132 | 4 | private function getInputValue($valueKey, $question, $hideAnswer = false) |
|
133 | { |
||
134 | 4 | $_sValue = $this->input->getOption($valueKey); |
|
135 | 4 | if (empty($_sValue)) { |
|
136 | 3 | $_sValue = $this->printQuestion( |
|
137 | 3 | $question, |
|
138 | 3 | $this->getParameterValue($valueKey), |
|
139 | 3 | $hideAnswer |
|
140 | ); |
||
141 | } |
||
142 | |||
143 | 4 | return $_sValue; |
|
144 | } |
||
145 | |||
146 | /** |
||
147 | * @param array $userInput |
||
148 | */ |
||
149 | 3 | private function saveParameters(array $userInput) |
|
150 | { |
||
151 | // We implemented an additional level of information |
||
152 | // into the user input array: Is this field required or not? |
||
153 | // To be backwards compatible we only store the value of |
||
154 | // the question in the dump file. |
||
155 | // With this loop we get rid of the "required" information |
||
156 | // from getInputValues(). |
||
157 | 3 | $toStore = []; |
|
158 | 3 | foreach ($userInput as $key => $value) { |
|
159 | 3 | $toStore[$key] = ('null' === $value['value']) ? null : $value['value']; |
|
160 | } |
||
161 | |||
162 | $configToSave = [ |
||
163 | 3 | $this->getProfileName() => [ |
|
164 | 3 | 'parameters' => $toStore |
|
165 | ] |
||
166 | ]; |
||
167 | |||
168 | 3 | $path = $this->getHomeDir() . DIRECTORY_SEPARATOR . $this->getParameterFileName(); |
|
169 | |||
170 | // load exiting config to merge |
||
171 | 3 | $config = $this->loadConfigFile(['profiles' => []]); |
|
172 | |||
173 | $finalConfig = [ |
||
174 | 3 | 'profiles' => array_merge($config['profiles'], $configToSave) |
|
175 | ]; |
||
176 | |||
177 | |||
178 | // dump final config |
||
179 | 3 | $dumper = new Dumper(); |
|
180 | 3 | $yaml = $dumper->dump($finalConfig, 4); |
|
181 | |||
182 | 3 | $fileSystem = new Filesystem(); |
|
183 | 3 | $fileSystem->dumpFile( |
|
184 | 3 | $path, |
|
185 | 3 | $yaml |
|
186 | ); |
||
187 | 3 | } |
|
188 | |||
189 | /** |
||
190 | * @param array $userInput |
||
191 | * @return bool |
||
192 | */ |
||
193 | 4 | private function hasValidateUserInput(array $userInput) |
|
204 | |||
205 | /** |
||
206 | * @param string $key |
||
207 | * @param mixed $defaultValue |
||
208 | * @return mixed |
||
209 | */ |
||
210 | 3 | private function getParameterValue($key, $defaultValue = null) |
|
220 | |||
221 | /** |
||
222 | * @return array |
||
223 | */ |
||
224 | 3 | private function getParameters() |
|
233 | |||
234 | /** |
||
235 | * @param mixed $defaultValue |
||
236 | * @return mixed |
||
237 | */ |
||
238 | 4 | private function loadConfigFile($defaultValue = []) |
|
254 | |||
255 | |||
256 | /** |
||
257 | * @param string $question |
||
258 | * @param null|mixed $defaultValue |
||
259 | * @param boolean $hideAnswer |
||
260 | * @return mixed |
||
261 | */ |
||
262 | 3 | private function printQuestion($question, $defaultValue = null, $hideAnswer = false) |
|
288 | } |
||
289 |