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 7c4add2

Browse filesBrowse files
committed
Fall back to default configuration in debug:config
1 parent 2cee75b commit 7c4add2
Copy full SHA for 7c4add2

File tree

6 files changed

+88
-14
lines changed
Filter options

6 files changed

+88
-14
lines changed

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

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

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Config\Definition\Processor;
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\ExtensionInterface;
2123
use Symfony\Component\Yaml\Yaml;
2224

2325
/**
@@ -77,22 +79,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7779
}
7880

7981
$extension = $this->findExtension($name);
80-
$container = $this->compileContainer();
81-
8282
$extensionAlias = $extension->getAlias();
83-
$extensionConfig = [];
84-
foreach ($container->getCompilerPassConfig()->getPasses() as $pass) {
85-
if ($pass instanceof ValidateEnvPlaceholdersPass) {
86-
$extensionConfig = $pass->getExtensionConfig();
87-
break;
88-
}
89-
}
90-
91-
if (!isset($extensionConfig[$extensionAlias])) {
92-
throw new \LogicException(sprintf('The extension with alias "%s" does not have configuration.', $extensionAlias));
93-
}
83+
$container = $this->compileContainer();
9484

95-
$config = $container->resolveEnvPlaceholders($extensionConfig[$extensionAlias]);
85+
$config = $container->resolveEnvPlaceholders($this->getConfigForExtension($extension, $container));
9686

9787
if (null === $path = $input->getArgument('path')) {
9888
$io->title(
@@ -153,4 +143,31 @@ private function getConfigForPath(array $config, string $path, string $alias)
153143

154144
return $config;
155145
}
146+
147+
/**
148+
* @return mixed
149+
*/
150+
private function getConfigForExtension(ExtensionInterface $extension, ContainerBuilder $container)
151+
{
152+
$extensionAlias = $extension->getAlias();
153+
154+
$extensionConfig = [];
155+
foreach ($container->getCompilerPassConfig()->getPasses() as $pass) {
156+
if ($pass instanceof ValidateEnvPlaceholdersPass) {
157+
$extensionConfig = $pass->getExtensionConfig();
158+
break;
159+
}
160+
}
161+
162+
if (isset($extensionConfig[$extensionAlias])) {
163+
return $extensionConfig[$extensionAlias];
164+
}
165+
166+
// Fall back to default config
167+
$configs = $container->getExtensionConfig($extensionAlias);
168+
$configuration = $extension->getConfiguration($configs, $container);
169+
$this->validateConfiguration($extension, $configuration);
170+
171+
return $container->resolveEnvPlaceholders((new Processor())->processConfiguration($configuration, $configs));
172+
}
156173
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class DefaultConfigTestBundle extends Bundle
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
class Configuration implements ConfigurationInterface
9+
{
10+
public function getConfigTreeBuilder(): TreeBuilder
11+
{
12+
$treeBuilder = new TreeBuilder('default_config_test');
13+
14+
$treeBuilder->getRootNode()
15+
->children()
16+
->scalarNode('foo')->defaultValue('bar')->end()
17+
->end();
18+
19+
return $treeBuilder;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Extension\Extension;
7+
8+
class DefaultConfigTestExtension extends Extension
9+
{
10+
public function load(array $configs, ContainerBuilder $container)
11+
{
12+
$configuration = new Configuration();
13+
$config = $this->processConfiguration($configuration, $configs);
14+
15+
$container->setParameter('default_config_test', $config['foo']);
16+
}
17+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public function testDumpWithPrefixedEnv()
7474
$this->assertStringContainsString("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'", $tester->getDisplay());
7575
}
7676

77+
public function testDumpFallsBackToBundleDefaultConfig()
78+
{
79+
$tester = $this->createCommandTester();
80+
$tester->execute(['name' => 'DefaultConfigTestBundle']);
81+
82+
$this->assertStringContainsString('foo: bar', $tester->getDisplay());
83+
}
84+
7785
private function createCommandTester(): CommandTester
7886
{
7987
$command = $this->application->find('debug:config');

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ConfigDump/bundles.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ConfigDump/bundles.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
*/
1111

1212
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle\DefaultConfigTestBundle;
1314
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
1415

1516
return [
17+
new DefaultConfigTestBundle(),
1618
new FrameworkBundle(),
1719
new TestBundle(),
1820
];

0 commit comments

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