Skip to content

Commit 850f3c1

Browse files
Merge branch '5.4' into 6.2
* 5.4: [FrameworkBundle] Show non-bundle extensions in `debug:config` & `config:dump` list view & completion
2 parents 5678626 + fa09aa4 commit 850f3c1

File tree

5 files changed

+111
-28
lines changed

5 files changed

+111
-28
lines changed

Command/AbstractConfigCommand.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,44 @@ protected function listBundles(OutputInterface|StyleInterface $output)
5454
}
5555
}
5656

57+
protected function listNonBundleExtensions(OutputInterface|StyleInterface $output): void
58+
{
59+
$title = 'Available registered non-bundle extension aliases';
60+
$headers = ['Extension alias'];
61+
$rows = [];
62+
63+
$kernel = $this->getApplication()->getKernel();
64+
65+
$bundleExtensions = [];
66+
foreach ($kernel->getBundles() as $bundle) {
67+
if ($extension = $bundle->getContainerExtension()) {
68+
$bundleExtensions[\get_class($extension)] = true;
69+
}
70+
}
71+
72+
$extensions = $this->getContainerBuilder($kernel)->getExtensions();
73+
74+
foreach ($extensions as $alias => $extension) {
75+
if (isset($bundleExtensions[\get_class($extension)])) {
76+
continue;
77+
}
78+
$rows[] = [$alias];
79+
}
80+
81+
if (!$rows) {
82+
return;
83+
}
84+
85+
if ($output instanceof StyleInterface) {
86+
$output->title($title);
87+
$output->table($headers, $rows);
88+
} else {
89+
$output->writeln($title);
90+
$table = new Table($output);
91+
$table->setHeaders($headers)->setRows($rows)->render();
92+
}
93+
}
94+
5795
protected function findExtension(string $name): ExtensionInterface
5896
{
5997
$bundles = $this->initializeBundles();

Command/ConfigDebugCommand.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7171

7272
if (null === $name = $input->getArgument('name')) {
7373
$this->listBundles($errorIo);
74-
75-
$kernel = $this->getApplication()->getKernel();
76-
if ($kernel instanceof ExtensionInterface
77-
&& ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)
78-
&& $kernel->getAlias()
79-
) {
80-
$errorIo->table(['Kernel Extension'], [[$kernel->getAlias()]]);
81-
}
74+
$this->listNonBundleExtensions($errorIo);
8275

8376
$errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
8477
$errorIo->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
@@ -181,7 +174,8 @@ private function getConfigForExtension(ExtensionInterface $extension, ContainerB
181174
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
182175
{
183176
if ($input->mustSuggestArgumentValuesFor('name')) {
184-
$suggestions->suggestValues($this->getAvailableBundles(!preg_match('/^[A-Z]/', $input->getCompletionValue())));
177+
$suggestions->suggestValues($this->getAvailableExtensions());
178+
$suggestions->suggestValues($this->getAvailableBundles());
185179

186180
return;
187181
}
@@ -196,11 +190,23 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
196190
}
197191
}
198192

199-
private function getAvailableBundles(bool $alias): array
193+
private function getAvailableExtensions(): array
194+
{
195+
$kernel = $this->getApplication()->getKernel();
196+
197+
$extensions = [];
198+
foreach ($this->getContainerBuilder($kernel)->getExtensions() as $alias => $extension) {
199+
$extensions[] = $alias;
200+
}
201+
202+
return $extensions;
203+
}
204+
205+
private function getAvailableBundles(): array
200206
{
201207
$availableBundles = [];
202208
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
203-
$availableBundles[] = $alias ? $bundle->getContainerExtension()->getAlias() : $bundle->getName();
209+
$availableBundles[] = $bundle->getName();
204210
}
205211

206212
return $availableBundles;

Command/ConfigDumpReferenceCommand.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
use Symfony\Component\Console\Input\InputOption;
2424
use Symfony\Component\Console\Output\OutputInterface;
2525
use Symfony\Component\Console\Style\SymfonyStyle;
26-
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
27-
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2826
use Symfony\Component\Yaml\Yaml;
2927

3028
/**
@@ -81,14 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8179

8280
if (null === $name = $input->getArgument('name')) {
8381
$this->listBundles($errorIo);
84-
85-
$kernel = $this->getApplication()->getKernel();
86-
if ($kernel instanceof ExtensionInterface
87-
&& ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)
88-
&& $kernel->getAlias()
89-
) {
90-
$errorIo->table(['Kernel Extension'], [[$kernel->getAlias()]]);
91-
}
82+
$this->listNonBundleExtensions($errorIo);
9283

9384
$errorIo->comment([
9485
'Provide the name of a bundle as the first argument of this command to dump its default configuration. (e.g. <comment>config:dump-reference FrameworkBundle</comment>)',
@@ -156,6 +147,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
156147
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
157148
{
158149
if ($input->mustSuggestArgumentValuesFor('name')) {
150+
$suggestions->suggestValues($this->getAvailableExtensions());
159151
$suggestions->suggestValues($this->getAvailableBundles());
160152
}
161153

@@ -164,13 +156,24 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
164156
}
165157
}
166158

159+
private function getAvailableExtensions(): array
160+
{
161+
$kernel = $this->getApplication()->getKernel();
162+
163+
$extensions = [];
164+
foreach ($this->getContainerBuilder($kernel)->getExtensions() as $alias => $extension) {
165+
$extensions[] = $alias;
166+
}
167+
168+
return $extensions;
169+
}
170+
167171
private function getAvailableBundles(): array
168172
{
169173
$bundles = [];
170174

171175
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
172176
$bundles[] = $bundle->getName();
173-
$bundles[] = $bundle->getContainerExtension()->getAlias();
174177
}
175178

176179
return $bundles;

Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@
2323
*/
2424
class ConfigDebugCommandTest extends AbstractWebTestCase
2525
{
26+
/**
27+
* @testWith [true]
28+
* [false]
29+
*/
30+
public function testShowList(bool $debug)
31+
{
32+
$tester = $this->createCommandTester($debug);
33+
$ret = $tester->execute([]);
34+
35+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
36+
$this->assertStringContainsString('Available registered bundles with their extension alias if available', $tester->getDisplay());
37+
$this->assertStringContainsString(' DefaultConfigTestBundle default_config_test', $tester->getDisplay());
38+
$this->assertStringContainsString(' ExtensionWithoutConfigTestBundle extension_without_config_test', $tester->getDisplay());
39+
$this->assertStringContainsString(' FrameworkBundle framework', $tester->getDisplay());
40+
$this->assertStringContainsString(' TestBundle test', $tester->getDisplay());
41+
$this->assertStringContainsString('Available registered non-bundle extension aliases', $tester->getDisplay());
42+
$this->assertStringContainsString(' foo', $tester->getDisplay());
43+
$this->assertStringContainsString(' test_dump', $tester->getDisplay());
44+
}
45+
2646
/**
2747
* @testWith [true]
2848
* [false]
@@ -201,14 +221,10 @@ public function testComplete(bool $debug, array $input, array $expectedSuggestio
201221

202222
public static function provideCompletionSuggestions(): \Generator
203223
{
204-
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test'];
224+
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test', 'foo', 'test_dump'];
205225
yield 'name, no debug' => [false, [''], $name];
206226
yield 'name, debug' => [true, [''], $name];
207227

208-
$nameCamelCased = ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
209-
yield 'name (started CamelCase), no debug' => [false, ['Fra'], $nameCamelCased];
210-
yield 'name (started CamelCase), debug' => [true, ['Fra'], $nameCamelCased];
211-
212228
$nameWithPath = ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale'];
213229
yield 'name with existing path, no debug' => [false, ['framework', ''], $nameWithPath];
214230
yield 'name with existing path, debug' => [true, ['framework', ''], $nameWithPath];

Tests/Functional/ConfigDumpReferenceCommandTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@
2323
*/
2424
class ConfigDumpReferenceCommandTest extends AbstractWebTestCase
2525
{
26+
/**
27+
* @testWith [true]
28+
* [false]
29+
*/
30+
public function testShowList(bool $debug)
31+
{
32+
$tester = $this->createCommandTester($debug);
33+
$ret = $tester->execute([]);
34+
35+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
36+
$this->assertStringContainsString('Available registered bundles with their extension alias if available', $tester->getDisplay());
37+
$this->assertStringContainsString(' DefaultConfigTestBundle default_config_test', $tester->getDisplay());
38+
$this->assertStringContainsString(' ExtensionWithoutConfigTestBundle extension_without_config_test', $tester->getDisplay());
39+
$this->assertStringContainsString(' FrameworkBundle framework', $tester->getDisplay());
40+
$this->assertStringContainsString(' TestBundle test', $tester->getDisplay());
41+
$this->assertStringContainsString('Available registered non-bundle extension aliases', $tester->getDisplay());
42+
$this->assertStringContainsString(' foo', $tester->getDisplay());
43+
$this->assertStringContainsString(' test_dump', $tester->getDisplay());
44+
}
45+
2646
/**
2747
* @testWith [true]
2848
* [false]
@@ -120,7 +140,7 @@ public function testComplete(bool $debug, array $input, array $expectedSuggestio
120140

121141
public static function provideCompletionSuggestions(): iterable
122142
{
123-
$name = ['DefaultConfigTestBundle', 'default_config_test', 'ExtensionWithoutConfigTestBundle', 'extension_without_config_test', 'FrameworkBundle', 'framework', 'TestBundle', 'test'];
143+
$name = ['foo', 'default_config_test', 'extension_without_config_test', 'framework', 'test', 'test_dump', 'DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
124144
yield 'name, no debug' => [false, [''], $name];
125145
yield 'name, debug' => [true, [''], $name];
126146

0 commit comments

Comments
 (0)