Skip to content

Commit 0af9d95

Browse files
author
Adrien Jourdier
committed
Fix debug:config completion
1 parent a75f1d7 commit 0af9d95

File tree

2 files changed

+31
-37
lines changed

2 files changed

+31
-37
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,11 @@ protected function configure()
5252
->setHelp(<<<'EOF'
5353
The <info>%command.name%</info> command dumps the current configuration for an
5454
extension/bundle.
55-
5655
Either the extension alias or bundle name can be used:
57-
5856
<info>php %command.full_name% framework</info>
5957
<info>php %command.full_name% FrameworkBundle</info>
60-
6158
For dumping a specific option, add its path as second argument:
62-
6359
<info>php %command.full_name% framework serializer.enabled</info>
64-
6560
EOF
6661
)
6762
;
@@ -190,36 +185,26 @@ private function getConfigForExtension(ExtensionInterface $extension, ContainerB
190185
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
191186
{
192187
if ($input->mustSuggestArgumentValuesFor('name')) {
193-
$suggestions->suggestValues($this->getAvailableBundles());
188+
$suggestions->suggestValues($this->getAvailableBundles(!preg_match('/[A-Z]/', $input->getCompletionValue()[0] ?? '')));
194189

195190
return;
196191
}
197192

198193
if ($input->mustSuggestArgumentValuesFor('path') && null !== $name = $input->getArgument('name')) {
199-
$path = $input->getArgument('path');
200-
$extension = $this->findExtension($name);
201-
$extensionAlias = $extension->getAlias();
202-
$container = $this->compileContainer();
203-
204194
try {
205-
$config = $this->getConfigForPath($this->getConfig($extension, $container), $path, $extensionAlias);
195+
$config = $this->getConfig($this->findExtension($name), $this->compileContainer());
196+
$paths = array_keys(self::buildPathsCompletion($config));
197+
$suggestions->suggestValues($paths);
206198
} catch (LogicException $e) {
207-
$config = [];
208199
}
209-
210-
$suggestions->suggestValues(array_keys($config));
211200
}
212201
}
213202

214-
private function getAvailableBundles(): array
203+
private function getAvailableBundles(bool $alias): array
215204
{
216205
$availableBundles = [];
217206
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
218-
$availableBundles[] = $bundle->getName();
219-
220-
if ($extension = $bundle->getContainerExtension()) {
221-
$availableBundles[] = $extension->getAlias();
222-
}
207+
$availableBundles[] = $alias ? $bundle->getContainerExtension()->getAlias() : $bundle->getName();
223208
}
224209

225210
return $availableBundles;
@@ -233,4 +218,18 @@ private function getConfig(ExtensionInterface $extension, ContainerBuilder $cont
233218
)
234219
);
235220
}
221+
222+
private static function buildPathsCompletion(array $paths, string $prefix = ''): array
223+
{
224+
$completionPaths = [];
225+
foreach ($paths as $key => $values) {
226+
if (\is_array($values)) {
227+
$completionPaths = $completionPaths + self::buildPathsCompletion($values, $prefix . $key . '.');
228+
} else {
229+
$completionPaths[$prefix.$key] = null;
230+
}
231+
}
232+
233+
return $completionPaths;
234+
}
236235
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,41 +122,36 @@ public function testComplete(array $input, array $expectedSuggestions)
122122

123123
$tester = new CommandCompletionTester($this->application->get('debug:config'));
124124

125-
$suggestions = $tester->complete($input, 2);
125+
$suggestions = $tester->complete($input);
126126

127-
$this->assertSame($expectedSuggestions, $suggestions);
127+
foreach ($expectedSuggestions as $expectedSuggestion) {
128+
$this->assertContains($expectedSuggestion, $suggestions);
129+
}
128130
}
129131

130132
public function provideCompletionSuggestions(): \Generator
131133
{
132134
yield 'name' => [
133135
[''],
134136
[
135-
'DefaultConfigTestBundle',
136137
'default_config_test',
137-
'ExtensionWithoutConfigTestBundle',
138138
'extension_without_config_test',
139-
'FrameworkBundle',
140139
'framework',
141-
'TestBundle',
142140
'test',
143141
],
144142
];
145143

146144
yield 'name with existing path' => [
147-
['framework', 'uid'],
145+
['framework', ''],
148146
[
149-
'enabled',
150-
'default_uuid_version',
151-
'name_based_uuid_version',
152-
'time_based_uuid_version',
147+
'secret',
148+
'router.resource',
149+
'router.utf8',
150+
'router.enabled',
151+
'validation.enabled',
152+
'default_locale',
153153
],
154154
];
155-
156-
yield 'name with unknown path' => [
157-
['default_config_test', 'uid'],
158-
[],
159-
];
160155
}
161156

162157
private function createCommandTester(): CommandTester

0 commit comments

Comments
 (0)