Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c74ff4

Browse filesBrowse files
feature #36186 [FrameworkBundle] Dump kernel extension configuration (guillbdx)
This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [FrameworkBundle] Dump kernel extension configuration | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #34756 | License | MIT If the kernel is a container extension and defines a configuration, the `config:dump-reference` will now be able to dump it. Commits ------- 2ccafb1 [FrameworkBundle] Dump kernel extension configuration
2 parents 0876480 + 2ccafb1 commit 0c74ff4
Copy full SHA for 0c74ff4

File tree

Expand file treeCollapse file tree

7 files changed

+94
-4
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+94
-4
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CHANGELOG
1616
* Added tag `routing.expression_language_function` to define functions available in route conditions
1717
* Added `debug:container --deprecations` option to see compile-time deprecations.
1818
* Made `BrowserKitAssertionsTrait` report the original error message in case of a failure
19+
* Added ability for `config:dump-reference` and `debug:config` to dump and debug kernel container extension configuration.
1920

2021
5.0.0
2122
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Helper\Table;
1717
use Symfony\Component\Console\Output\OutputInterface;
1818
use Symfony\Component\Console\Style\StyleInterface;
19+
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
1920
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2021

2122
/**
@@ -64,6 +65,22 @@ protected function findExtension(string $name)
6465
$bundles = $this->initializeBundles();
6566
$minScore = INF;
6667

68+
$kernel = $this->getApplication()->getKernel();
69+
if ($kernel instanceof ExtensionInterface && ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)) {
70+
if ($name === $kernel->getAlias()) {
71+
return $kernel;
72+
}
73+
74+
if ($kernel->getAlias()) {
75+
$distance = levenshtein($name, $kernel->getAlias());
76+
77+
if ($distance < $minScore) {
78+
$guess = $kernel->getAlias();
79+
$minScore = $distance;
80+
}
81+
}
82+
}
83+
6784
foreach ($bundles as $bundle) {
6885
if ($name === $bundle->getName()) {
6986
if (!$bundle->getContainerExtension()) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Config\Definition\ConfigurationInterface;
1415
use Symfony\Component\Console\Exception\LogicException;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
2021
use Symfony\Component\DependencyInjection\ContainerBuilder;
22+
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
23+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2124
use Symfony\Component\Yaml\Yaml;
2225

2326
/**
@@ -70,6 +73,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7073

7174
if (null === $name = $input->getArgument('name')) {
7275
$this->listBundles($errorIo);
76+
77+
$kernel = $this->getApplication()->getKernel();
78+
if ($kernel instanceof ExtensionInterface
79+
&& ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)
80+
&& $kernel->getAlias()
81+
) {
82+
$errorIo->table(['Kernel Extension'], [[$kernel->getAlias()]]);
83+
}
84+
7385
$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>)');
7486
$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)');
7587

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Config\Definition\ConfigurationInterface;
1415
use Symfony\Component\Config\Definition\Dumper\XmlReferenceDumper;
1516
use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper;
1617
use Symfony\Component\Console\Exception\InvalidArgumentException;
@@ -19,6 +20,8 @@
1920
use Symfony\Component\Console\Input\InputOption;
2021
use Symfony\Component\Console\Output\OutputInterface;
2122
use Symfony\Component\Console\Style\SymfonyStyle;
23+
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
24+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2225

2326
/**
2427
* A console command for dumping available configuration reference.
@@ -81,6 +84,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8184

8285
if (null === $name = $input->getArgument('name')) {
8386
$this->listBundles($errorIo);
87+
88+
$kernel = $this->getApplication()->getKernel();
89+
if ($kernel instanceof ExtensionInterface
90+
&& ($kernel instanceof ConfigurationInterface || $kernel instanceof ConfigurationExtensionInterface)
91+
&& $kernel->getAlias()
92+
) {
93+
$errorIo->table(['Kernel Extension'], [[$kernel->getAlias()]]);
94+
}
95+
8496
$errorIo->comment([
8597
'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>)',
8698
'For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>config:dump-reference FrameworkBundle profiler.matcher</comment> to dump the <comment>framework.profiler.matcher</comment> configuration)',
@@ -91,7 +103,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
91103

92104
$extension = $this->findExtension($name);
93105

94-
$configuration = $extension->getConfiguration([], $this->getContainerBuilder());
106+
if ($extension instanceof ConfigurationInterface) {
107+
$configuration = $extension;
108+
} else {
109+
$configuration = $extension->getConfiguration([], $this->getContainerBuilder());
110+
}
95111

96112
$this->validateConfiguration($extension, $configuration);
97113

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ protected function setUp(): void
3030
$this->application->doRun(new ArrayInput([]), new NullOutput());
3131
}
3232

33+
public function testDumpKernelExtension()
34+
{
35+
$tester = $this->createCommandTester();
36+
$ret = $tester->execute(['name' => 'foo']);
37+
$this->assertStringContainsString('foo:', $tester->getDisplay());
38+
$this->assertStringContainsString(' bar', $tester->getDisplay());
39+
}
40+
3341
public function testDumpBundleName()
3442
{
3543
$tester = $this->createCommandTester();

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php
+32-1Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app;
1313

1414
use Psr\Log\NullLogger;
15+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16+
use Symfony\Component\Config\Definition\ConfigurationInterface;
1517
use Symfony\Component\Config\Loader\LoaderInterface;
1618
use Symfony\Component\DependencyInjection\ContainerBuilder;
1719
use Symfony\Component\DependencyInjection\ContainerInterface;
20+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
1821
use Symfony\Component\Filesystem\Filesystem;
1922
use Symfony\Component\HttpKernel\Kernel;
2023

@@ -23,7 +26,7 @@
2326
*
2427
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
2528
*/
26-
class AppKernel extends Kernel
29+
class AppKernel extends Kernel implements ExtensionInterface, ConfigurationInterface
2730
{
2831
private $varDir;
2932
private $testCase;
@@ -106,4 +109,32 @@ public function getContainer(): ContainerInterface
106109

107110
return parent::getContainer();
108111
}
112+
113+
public function getConfigTreeBuilder()
114+
{
115+
$treeBuilder = new TreeBuilder('foo');
116+
$rootNode = $treeBuilder->getRootNode();
117+
$rootNode->children()->scalarNode('foo')->defaultValue('bar')->end()->end();
118+
119+
return $treeBuilder;
120+
}
121+
122+
public function load(array $configs, ContainerBuilder $container)
123+
{
124+
}
125+
126+
public function getNamespace()
127+
{
128+
return '';
129+
}
130+
131+
public function getXsdValidationBasePath()
132+
{
133+
return false;
134+
}
135+
136+
public function getAlias()
137+
{
138+
return 'foo';
139+
}
109140
}

‎src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\Config\Definition\BaseNode;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
1516
use Symfony\Component\Config\Definition\Processor;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
@@ -68,14 +69,18 @@ public function process(ContainerBuilder $container)
6869
$processor = new Processor();
6970

7071
foreach ($extensions as $name => $extension) {
71-
if (!$extension instanceof ConfigurationExtensionInterface || !$config = array_filter($container->getExtensionConfig($name))) {
72+
if (!($extension instanceof ConfigurationExtensionInterface || $extension instanceof ConfigurationInterface)
73+
|| !$config = array_filter($container->getExtensionConfig($name))
74+
) {
7275
// this extension has no semantic configuration or was not called
7376
continue;
7477
}
7578

7679
$config = $resolvingBag->resolveValue($config);
7780

78-
if (null === $configuration = $extension->getConfiguration($config, $container)) {
81+
if ($extension instanceof ConfigurationInterface) {
82+
$configuration = $extension;
83+
} elseif (null === $configuration = $extension->getConfiguration($config, $container)) {
7984
continue;
8085
}
8186

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.