|
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
8000
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,53 @@ 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 | + $name = strtolower($input->getArgument('name')); |
| 193 | + |
| 194 | + if ($input->mustSuggestArgumentValuesFor('name')) { |
| 195 | + $suggestions->suggestValues($this->getBundlesCompletion($name)); |
| 196 | + } |
| 197 | + |
| 198 | + if ($input->mustSuggestArgumentValuesFor('path') && null !== $name) { |
| 199 | + $path = $input->getArgument('path'); |
| 200 | + $extension = $this->findExtension($name); |
| 201 | + $extensionAlias = $extension->getAlias(); |
| 202 | + $container = $this->compileContainer(); |
| 203 | + |
| 204 | + try { |
| 205 | + $config = $this->getConfigForPath($this->getConfig($extension, $container), $path, $extensionAlias); |
| 206 | + } catch (LogicException $e) { |
| 207 | + $config = []; |
| 208 | + } |
| 209 | + |
| 210 | + $suggestions->suggestValues(array_keys($config)); |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + private function getBundlesCompletion(string $name): array |
| 215 | + { |
| 216 | + $bundles = []; |
| 217 | + foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) { |
| 218 | + $bundleName = $bundle->getName(); |
| 219 | + $bundleAlias = $bundle->getContainerExtension()->getAlias(); |
| 220 | + |
| 221 | + if (str_starts_with(strtolower($bundleName), $name)) { |
| 222 | + $bundles[] = $bundleName; |
| 223 | + $bundles[] = $bundleAlias; |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + return $bundles; |
| 228 | + } |
| 229 | + |
| 230 | + private function getConfig(ExtensionInterface $extension, ContainerBuilder $container) |
| 231 | + { |
| 232 | + return $container->resolveEnvPlaceholders( |
| 233 | + $container->getParameterBag()->resolveValue( |
| 234 | + $this->getConfigForExtension($extension, $container) |
| 235 | + ) |
| 236 | + ); |
| 237 | + } |
191 | 238 | }
|
0 commit comments