Skip to content

Commit b16b1dc

Browse files
Merge branch '6.2' into 6.3
* 6.2: [FrameworkBundle] Show non-bundle extensions in `debug:config` & `config:dump` list view & completion
2 parents 8ffdd91 + b66e6db commit b16b1dc

File tree

5 files changed

+111
-28
lines changed

5 files changed

+111
-28
lines changed

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

+38
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,44 @@ protected function listBundles(OutputInterface|StyleInterface $output)
5252
}
5353
}
5454

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

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

+17-11
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8181

8282
if (null === $name = $input->getArgument('name')) {
8383
$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-
}
84+
$this->listNonBundleExtensions($errorIo);
9285

9386
$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>)');
9487
$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)');
@@ -208,7 +201,8 @@ private function getConfigForExtension(ExtensionInterface $extension, ContainerB
208201
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
209202
{
210203
if ($input->mustSuggestArgumentValuesFor('name')) {
211-
$suggestions->suggestValues($this->getAvailableBundles(!preg_match('/^[A-Z]/', $input->getCompletionValue())));
204+
$suggestions->suggestValues($this->getAvailableExtensions());
205+
$suggestions->suggestValues($this->getAvailableBundles());
212206

213207
return;
214208
}
@@ -227,11 +221,23 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
227221
}
228222
}
229223

230-
private function getAvailableBundles(bool $alias): array
224+
private function getAvailableExtensions(): array
225+
{
226+
$kernel = $this->getApplication()->getKernel();
227+
228+
$extensions = [];
229+
foreach ($this->getContainerBuilder($kernel)->getExtensions() as $alias => $extension) {
230+
$extensions[] = $alias;
231+
}
232+
233+
return $extensions;
234+
}
235+
236+
private function getAvailableBundles(): array
231237
{
232238
$availableBundles = [];
233239
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
234-
$availableBundles[] = $alias ? $bundle->getContainerExtension()->getAlias() : $bundle->getName();
240+
$availableBundles[] = $bundle->getName();
235241
}
236242

237243
return $availableBundles;

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

+14-11
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
/**
@@ -83,14 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8381

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

9586
$errorIo->comment([
9687
'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>)',
@@ -158,6 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
158149
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
159150
{
160151
if ($input->mustSuggestArgumentValuesFor('name')) {
152+
$suggestions->suggestValues($this->getAvailableExtensions());
161153
$suggestions->suggestValues($this->getAvailableBundles());
162154
}
163155

@@ -166,13 +158,24 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
166158
}
167159
}
168160

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

173177
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
174178
$bundles[] = $bundle->getName();
175-
$bundles[] = $bundle->getContainerExtension()->getAlias();
176179
}
177180

178181
return $bundles;

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

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

220240
public static function provideCompletionSuggestions(): \Generator
221241
{
222-
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test'];
242+
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test', 'foo', 'test_dump'];
223243
yield 'name, no debug' => [false, [''], $name];
224244
yield 'name, debug' => [true, [''], $name];
225245

226-
$nameCamelCased = ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
227-
yield 'name (started CamelCase), no debug' => [false, ['Fra'], $nameCamelCased];
228-
yield 'name (started CamelCase), debug' => [true, ['Fra'], $nameCamelCased];
229-
230246
$nameWithPath = ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale'];
231247
yield 'name with existing path, no debug' => [false, ['framework', ''], $nameWithPath];
232248
yield 'name with existing path, debug' => [true, ['framework', ''], $nameWithPath];

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

+21-1
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)