8000 [FrameworkBundle] Show non-bundle extensions in `debug:config` & `config:dump` list view & completion by HypeMC · Pull Request #50548 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div id="js-flash-container" class="flash-container" data-turbo-replace>

[FrameworkBundle] Show non-bundle extensions in debug:config & config:dump list view & completion #50548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,47 @@ protected function listBundles($output)
}
}

/**
* @param OutputInterface|StyleInterface $output
*/
protected function listNonBundleExtensions($output)
{
$title = 'Available registered non-bundle extension aliases';
$headers = ['Extension alias'];
$rows = [];

$kernel = $this->getApplication()->getKernel();

$bundleExtensions = [];
foreach ($kernel->getBundles() as $bundle) {
if ($extension = $bundle->getContainerExtension()) {
$bundleExtensions[\get_class($extension)] = true;
}
}

$extensions = $this->getContainerBuilder($kernel)->getExtensions();

foreach ($extensions as $alias => $extension) {
if (isset($bundleExtensions[\get_class($extension)])) {
continue;
}
$rows[] = [$alias];
}

if (!$rows) {
return;
}

if ($output instanceof StyleInterface) {
$output->title($title);
$output->table($headers, $rows);
} else {
$output->writeln($title);
$table = new Table($output);
$table->setHeaders($headers)->setRows($rows)->render();
}
}

/**
* @return ExtensionInterface
*/
Expand Down
28 changes: 17 additions & 11 deletions src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (null === $name = $input->getArgument('name')) {
$this->listBundles($errorIo);

$kernel = $this->getApplication()->getKernel();
if ($kernel instanceof ExtensionInterface
&& ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)
&& $kernel->getAlias()
) {
$errorIo->table(['Kernel Extension'], [[$kernel->getAlias()]]);
}
$this->listNonBundleExtensions($errorIo);

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

return;
}
Expand All @@ -205,11 +199,23 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
}
}

private function getAvailableBundles(bool $alias): array
private function getAvailableExtensions(): array
{
$kernel = $this->getApplication()->getKernel();

$extensions = [];
foreach ($this->getContainerBuilder($kernel)->getExtensions() as $alias => $extension) {
$extensions[] = $alias;
}

return $extensions;
}

private function getAvailableBundles(): array
{
$availableBundles = [];
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
$availableBundles[] = $alias ? $bundle->getContainerExtension()->getAlias() : $bundle->getName();
$availableBundles[] = $bundle->getName();
}

return $availableBundles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\Yaml\Yaml;

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

if (null === $name = $input->getArgument('name')) {
$this->listBundles($errorIo);

$kernel = $this->getApplication()->getKernel();
if ($kernel instanceof ExtensionInterface
&& ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)
&& $kernel->getAlias()
) {
$errorIo->table(['Kernel Extension'], [[$kernel->getAlias()]]);
}
$this->listNonBundleExtensions($errorIo);

$errorIo->comment([
'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>)',
Expand Down Expand Up @@ -163,6 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestArgumentValuesFor('name')) {
$suggestions->suggestValues($this->getAvailableExtensions());
$suggestions->suggestValues($this->getAvailableBundles());
}

Expand All @@ -171,13 +163,24 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
}
}

private function getAvailableExtensions(): array
{
$kernel = $this->getApplication()->getKernel();

$extensions = [];
foreach ($this->getContainerBuilder($kernel)->getExtensions() as $alias => $extension) {
$extensions[] = $alias;
}

return $extensions;
}

private function getAvailableBundles(): array
{
$bundles = [];

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

return $bundles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@
*/
class ConfigDebugCommandTest extends AbstractWebTestCase
{
/**
* @testWith [true]
* [false]
*/
public function testShowList(bool $debug)
{
$tester = $this->createCommandTester($debug);
$ret = $tester->execute([]);

$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('Available registered bundles with their extension alias if available', $tester->getDisplay());
$this->assertStringContainsString(' DefaultConfigTestBundle default_config_test', $tester->getDisplay());
$this->assertStringContainsString(' ExtensionWithoutConfigTestBundle extension_without_config_test', $tester->getDisplay());
$this->assertStringContainsString(' FrameworkBundle framework', $tester->getDisplay());
$this->assertStringContainsString(' TestBundle test', $tester->getDisplay());
$this->assertStringContainsString('Available registered non-bundle extension aliases', $tester->getDisplay());
$this->assertStringContainsString(' foo', $tester->getDisplay());
$this->assertStringContainsString(' test_dump', $tester->getDisplay());
}

/**
* @testWith [true]
* [false]
Expand Down Expand Up @@ -185,14 +205,10 @@ public function testComplete(bool $debug, array $input, array $expectedSuggestio

public static function provideCompletionSuggestions(): \Generator
{
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test'];
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test', 'foo', 'test_dump'];
yield 'name, no debug' => [false, [''], $name];
yield 'name, debug' => [true, [''], $name];

$nameCamelCased = ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
yield 'name (started CamelCase), no debug' => [false, ['Fra'], $nameCamelCased];
yield 'name (started CamelCase), debug' => [true, ['Fra'], $nameCamelCased];

$nameWithPath = ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale'];
yield 'name with existing path, no debug' => [false, ['framework', ''], $nameWithPath];
yield 'name with existing path, debug' => [true, ['framework', ''], $nameWithPath];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@
*/
class ConfigDumpReferenceCommandTest extends AbstractWebTestCase
{
/**
* @testWith [true]
* [false]
*/
public function testShowList(bool $debug)
{
$tester = $this->createCommandTester($debug);
$ret = $tester->execute([]);

$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('Available registered bundles with their extension alias if available', $tester->getDisplay());
$this->assertStringContainsString(' DefaultConfigTestBundle default_config_test', $tester->getDisplay());
$this->assertStringContainsString(' ExtensionWithoutConfigTestBundle extension_without_config_test', $tester->getDisplay());
$this->assertStringContainsString(' FrameworkBundle framework', $tester->getDisplay());
$this->assertStringContainsString(' TestBundle test', $tester->getDisplay());
$this->assertStringContainsString('Available registered non-bundle extension aliases', $tester->getDisplay());
$this->assertStringContainsString(' foo', $tester->getDisplay());
$this->assertStringContainsString(' test_dump', $tester->getDisplay());
}

/**
* @testWith [true]
* [false]
Expand Down Expand Up @@ -120,7 +140,7 @@ public function testComplete(bool $debug, array $input, array $expectedSuggestio

public static function provideCompletionSuggestions(): iterable
{
$name = ['DefaultConfigTestBundle', 'default_config_test', 'ExtensionWithoutConfigTestBundle', 'extension_without_config_test', 'FrameworkBundle', 'framework', 'TestBundle', 'test'];
$name = ['foo', 'default_config_test', 'extension_without_config_test', 'framework', 'test', 'test_dump', 'DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
yield 'name, no debug' => [false, [''], $name];
yield 'name, debug' => [true, [''], $name];

Expand Down
0