8000 [FrameworkBundle] Show non-bundle extensions in `debug:config` & `con… · symfony/symfony@bfe288e · GitHub
[go: up one dir, main page]

Skip to content

Commit bfe288e

Browse files
committed
[FrameworkBundle] Show non-bundle extensions in debug:config & config:dump list view & completion
1 parent 3e677ed commit bfe288e

File tree

7 files changed

+116
-29
lines changed

7 files changed

+116
-29
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Show non-bundle extensions in `debug:config` and `config:dump-reference`
8+
list view and completion
9+
410
6.3
511
---
612

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

Lines changed: 38 additions & 0 deletions
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)
56+
{
57+
$title = 'Available registered extension aliases not from a bundle';
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[$extension::class] = true;
67+
}
68+
}
69+
70+
$extensions = $this->getContainerBuilder($kernel)->getExtensions();
71+
72+
foreach ($extensions as $alias => $extension) {
73+
if (isset($bundleExtensions[$extension::class])) {
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/BuildDebugContainerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilde
5555
$this->prepareContainer($containerBuilder);
5656

5757
return $containerBuilder;
58-
}, $kernel, \get_class($kernel));
58+
}, $kernel, $kernel::class);
5959
$container = $buildContainer();
6060
(new XmlFileLoader($container, new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
6161
$locatorPass = new ServiceLocatorTagPass();

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

Lines changed: 17 additions & 11 deletions
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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
< 10000 div class="diff-text-inner color-fg-muted">@@ -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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@
2424
*/
2525
class ConfigDebugCommandTest extends AbstractWebTestCase
2626
{
27+
/**
28+
* @dataProvider provideDebugValues
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 extension aliases not from a bundle', $tester->getDisplay());
42+
$this->assertStringContainsString(' foo', $tester->getDisplay());
43+
$this->assertStringContainsString(' test_dump', $tester->getDisplay());
44+
}
45+
2746
/**
2847
* @dataProvider provideDebugValues
2948
*/
@@ -212,14 +231,10 @@ public function testComplete(bool $debug, array $input, array $expectedSuggestio
212231

213232
public static function provideCompletionSuggestions(): \Generator
214233
{
215-
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test'];
234+
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test', 'foo', 'test_dump'];
216235
yield 'name, no debug' => [false, [''], $name];
217236
yield 'name, debug' => [true, [''], $name];
218237

219-
$nameCamelCased = ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
220-
yield 'name (started CamelCase), no debug' => [false, ['Fra'], $nameCamelCased];
221-
yield 'name (started CamelCase), debug' => [true, ['Fra'], $nameCamelCased];
222-
223238
$nameWithPath = ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale'];
224239
yield 'name with existing path, no debug' => [false, ['framework', ''], $nameWithPath];
225240
yield 'name with existing path, debug' => [true, ['framework', ''], $nameWithPath];

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

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

122141
public static function provideCompletionSuggestions(): iterable
123142
{
124-
$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'];
125144
yield 'name, no debug' => [false, [''], $name];
126145
yield 'name, debug' => [true, [''], $name];
127146

0 commit comments

Comments
 (0)
0