8000 bug #50548 [FrameworkBundle] Show non-bundle extensions in `debug:con… · symfony/symfony@a267738 · GitHub
[go: up one dir, main page]

Skip to content

Commit a267738

Browse files
bug #50548 [FrameworkBundle] Show non-bundle extensions in debug:config & config:dump list view & completion (HypeMC)
This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Show non-bundle extensions in `debug:config` & `config:dump` list view & completion | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follow up to #50546 (should be merged first), adds non-bundle extensions to `debug:config` & `config:dump` list views: ```php class Kernel extends BaseKernel implements ExtensionInterface, ConfigurationInterface { use MicroKernelTrait; protected function build(ContainerBuilder $container) { $container->registerExtension(new MyExtension()); } public function getAlias() { return 'kernel'; } // ... } ``` ![image](https://github.com/symfony/symfony/assets/2445045/5c75d33a-155c-4602-abf8-8babc72286b6) Commits ------- b31f700 [FrameworkBundle] Show non-bundle extensions in `debug:config` & `config:dump` list view & completion
2 parents ca9a8c1 + b31f700 commit a267738

File tree

5 files changed

+114
-28
lines changed

5 files changed

+114
-28
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,47 @@ protected function listBundles($output)
5757
}
5858
}
5959

60+
/**
61+
* @param OutputInterface|StyleInterface $output
62+
*/
63+
protected function listNonBundleExtensions($output)
64+
{
65+
$title = 'Available registered non-bundle extension aliases';
66+
$headers = ['Extension alias'];
67+
$rows = [];
68+
69+
$kernel = $this->getApplication()->getKernel();
70+
71+
$bundleExtensions = [];
72+
foreach ($kernel->getBundles() as $bundle) {
73+
if ($extension = $bundle->getContainerExtension()) {
74+
$bundleExtensions[\get_class($extension)] = true;
75+
}
76+
}
77+
78+
$extensions = $this->getContainerBuilder($kernel)->getExtensions();
79+
80+
foreach ($extensions as $alias => $extension) {
81+
if (isset($bundleExtensions[\get_class($extension)])) {
82+
continue;
83+
}
84+
$rows[] = [$alias];
85+
}
86+
87+
if (!$rows) {
88+
return;
89+
}
90+
91+
if ($output instanceof StyleInterface) {
92+
$output->title($title);
93+
$output->table($headers, $rows);
94+
} else {
95+
$output->writeln($title);
96+
$table = new Table($output);
97+
$table->setHeaders($headers)->setRows($rows)->render();
98+
}
99+
}
100+
60101
/**
61102
* @return ExtensionInterface
62103
*/

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

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

7878
if (null === $name = $input->getArgument('name')) {
7979
$this->listBundles($errorIo);
80-
81-
$kernel = $this->getApplication()->getKernel();
82-
if ($kernel instanceof ExtensionInterface
83-
&& ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)
84-
&& $kernel->getAlias()
85-
) {
86-
$errorIo->table(['Kernel Extension'], [[$kernel->getAlias()]]);
87-
}
80+
$this->listNonBundleExtensions($errorIo);
8881

8982
$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>)');
9083
$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)');
@@ -190,7 +183,8 @@ private function getConfigForExtension(ExtensionInterface $extension, ContainerB
190183
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
191184
{
192185
if ($input->mustSuggestArgumentValuesFor('name')) {
193-
$suggestions->suggestValues($this->getAvailableBundles(!preg_match('/^[A-Z]/', $input->getCompletionValue())));
186+
$suggestions->suggestValues($this->getAvailableExtensions());
187+
$suggestions->suggestValues($this->getAvailableBundles());
194188

195189
return;
196190
}
@@ -205,11 +199,23 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
205199
}
206200
}
207201

208-
private function getAvailableBundles(bool $alias): array
202+
private function getAvailableExtensions(): array
203+
{
204+
$kernel = $this->getApplication()->getKernel();
205+
206+
$extensions = [];
207+
foreach ($this->getContainerBuilder($kernel)->getExtensions() as $alias => $extension) {
208+
$extensions[] = $alias;
209+
}
210+
211+
return $extensions;
212+
}
213+
214+
private function getAvailableBundles(): array
209215
{
210216
$availableBundles = [];
211217
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
212-
$availableBundles[] = $alias ? $bundle->getContainerExtension()->getAlias() : $bundle->getName();
218+
$availableBundles[] = $bundle->getName();
213219
}
214220

215221
return $availableBundles;

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

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

2927
/**
@@ -88,14 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8886

8987
if (null === $name = $input->getArgument('name')) {
9088
$this->listBundles($errorIo);
91-
92-
$kernel = $this->getApplication()->getKernel();
93-
if ($kernel instanceof ExtensionInterface
94-
&& ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)
95-
&& $kernel->getAlias()
96-
) {
97-
$errorIo->table(['Kernel Extension'], [[$kernel->getAlias()]]);
98-
}
89+
$this->listNonBundleExtensions($errorIo);
9990

10091
$errorIo->comment([
10192
'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>)',
@@ -163,6 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
163154
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
164155
{
165156
if ($input->mustSuggestArgumentValuesFor('name')) {
157+
$suggestions->suggestValues($this->getAvailableExtensions());
166158
$suggestions->suggestValues($this->getAvailableBundles());
167159
}
168160

@@ -171,13 +163,24 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
171163
}
172164
}
173165

166+
private function getAvailableExtensions(): array
167+
{
168+
$kernel = $this->getApplication()->getKernel();
169+
170+
$extensions = [];
171+
foreach ($this->getContainerBuilder($kernel)->getExtensions() as $alias => $extension) {
172+
$extensions[] = $alias;
173+
}
174+
175+
return $extensions;
176+
}
177+
174178
private function getAvailableBundles(): array
175179
{
176180
$bundles = [];
177181

178182
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
179183
$bundles[] = $bundle->getName();
180-
$bundles[] = $bundle->getContainerExtension()->getAlias();
181184
}
182185

183186
return $bundles;

src/Symfony/Bundle/FrameworkBundle/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]
@@ -185,14 +205,10 @@ public function testComplete(bool $debug, array $input, array $expectedSuggestio
185205

186206
public static function provideCompletionSuggestions(): \Generator
187207
{
188-
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test'];
208+
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test', 'foo', 'test_dump'];
189209
yield 'name, no debug' => [false, [''], $name];
190210
yield 'name, debug' => [true, [''], $name];
191211

192-
$nameCamelCased = ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
193-
yield 'name (started CamelCase), no debug' => [false, ['Fra'], $nameCamelCased];
194-
yield 'name (started CamelCase), debug' => [true, ['Fra'], $nameCamelCased];
195-
196212
$nameWithPath = ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale'];
197213
yield 'name with existing path, no debug' => [false, ['framework', ''], $nameWithPath];
198214
yield 'name with existing path, debug' => [true, ['framework', ''], $nameWithPath];

src/Symfony/Bundle/FrameworkBundle/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)
0