|
13 | 13 |
|
14 | 14 | use Symfony\Component\Config\Definition\ConfigurationInterface;
|
15 | 15 | use Symfony\Component\Config\Definition\Processor;
|
| 16 | +use Symfony\Component\Console\Completion\CompletionInput; |
| 17 | +use Symfony\Component\Console\Completion\CompletionSuggestions; |
16 | 18 | use Symfony\Component\Console\Exception\LogicException;
|
17 | 19 | use Symfony\Component\Console\Input\InputArgument;
|
18 | 20 | use Symfony\Component\Console\Input\InputInterface;
|
@@ -94,11 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
94 | 96 | $extensionAlias = $extension->getAlias();
|
95 | 97 | $container = $this->compileContainer();
|
96 | 98 |
|
97 |
| - $config = $container->resolveEnvPlaceholders( |
98 |
| - $container->getParameterBag()->resolveValue( |
99 |
| - $this->getConfigForExtension($extension, $container) |
100 |
| - ) |
101 |
| - ); |
| 99 | + $config = $this->getConfig($extension, $container); |
102 | 100 |
|
103 | 101 | if (null === $path = $input->getArgument('path')) {
|
104 | 102 | $io->title(
|
@@ -188,4 +186,55 @@ private function getConfigForExtension(ExtensionInterface $extension, ContainerB
|
188 | 186 |
|
189 | 187 | return (new Processor())->processConfiguration($configuration, $configs);
|
190 | 188 | }
|
| 189 | + |
| 190 | + public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
| 191 | + { |
| 192 | + if ($input->mustSuggestArgumentValuesFor('name')) { |
| 193 | + $suggestions->suggestValues($this->getAvailableBundles(!preg_match('/^[A-Z]/', $input->getCompletionValue()))); |
| 194 | + |
| 195 | + return; |
| 196 | + } |
| 197 | + |
| 198 | + if ($input->mustSuggestArgumentValuesFor('path') && null !== $name = $input->getArgument('name')) { |
| 199 | + try { |
| 200 | + $config = $this->getConfig($this->findExtension($name), $this->compileContainer()); |
| 201 | + $paths = array_keys(self::buildPathsCompletion($config)); |
| 202 | + $suggestions->suggestValues($paths); |
| 203 | + } catch (LogicException $e) { |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + |
| 208 | + private function getAvailableBundles(bool $alias): array |
| 209 | + { |
| 210 | + $availableBundles = []; |
| 211 | + foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) { |
| 212 | + $availableBundles[] = $alias ? $bundle->getContainerExtension()->getAlias() : $bundle->getName(); |
| 213 | + } |
| 214 | + |
| 215 | + return $availableBundles; |
| 216 | + } |
| 217 | + |
| 218 | + private function getConfig(ExtensionInterface $extension, ContainerBuilder $container) |
| 219 | + { |
| 220 | + return $container->resolveEnvPlaceholders( |
| 221 | + $container->getParameterBag()->resolveValue( |
| 222 | + $this->getConfigForExtension($extension, $container) |
| 223 | + ) |
| 224 | + ); |
| 225 | + } |
| 226 | + |
| 227 | + private static function buildPathsCompletion(array $paths, string $prefix = ''): array |
| 228 | + { |
| 229 | + $completionPaths = []; |
| 230 | + foreach ($paths as $key => $values) { |
| 231 | + if (\is_array($values)) { |
| 232 | + $completionPaths = $completionPaths + self::buildPathsCompletion($values, $prefix.$key.'.'); |
| 233 | + } else { |
| 234 | + $completionPaths[$prefix.$key] = null; |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + return $completionPaths; |
| 239 | + } |
191 | 240 | }
|
0 commit comments