bug #30648 Debug finalized config in debug:config (ro0NL)
This PR was merged into the 4.2 branch.
Discussion
----------
Debug finalized config in debug:config
| Q | A
| ------------- | ---
| Branch? | 4.2
| Bug fix? | yes
| New feature? | no
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | #30637
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
Re-processing the extension config in `debug:config` causes a lot of steps to be ignored, basically everything in `ValidateEnvPlaceholdersPass`.
As such we trigger a misleading error when this command is invoked.
Commits
-------
b9ac3a52fb
Debug finalized config in debug:config
This commit is contained in:
commit
2d2cd40ba6
@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||||
|
|
||||||
use Symfony\Component\Config\Definition\Processor;
|
|
||||||
use Symfony\Component\Console\Exception\LogicException;
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
@ -80,15 +80,19 @@ EOF
|
|||||||
$container = $this->compileContainer();
|
$container = $this->compileContainer();
|
||||||
|
|
||||||
$extensionAlias = $extension->getAlias();
|
$extensionAlias = $extension->getAlias();
|
||||||
$configs = $container->getExtensionConfig($extensionAlias);
|
$extensionConfig = [];
|
||||||
$configuration = $extension->getConfiguration($configs, $container);
|
foreach ($container->getCompilerPassConfig()->getPasses() as $pass) {
|
||||||
|
if ($pass instanceof ValidateEnvPlaceholdersPass) {
|
||||||
|
$extensionConfig = $pass->getExtensionConfig();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->validateConfiguration($extension, $configuration);
|
if (!isset($extensionConfig[$extensionAlias])) {
|
||||||
|
throw new \LogicException(sprintf('The extension with alias "%s" does not have configuration.', $extensionAlias));
|
||||||
|
}
|
||||||
|
|
||||||
$configs = $container->resolveEnvPlaceholders($container->getParameterBag()->resolveValue($configs));
|
$config = $container->resolveEnvPlaceholders($extensionConfig[$extensionAlias]);
|
||||||
|
|
||||||
$processor = new Processor();
|
|
||||||
$config = $container->resolveEnvPlaceholders($container->getParameterBag()->resolveValue($processor->processConfiguration($configuration, $configs)));
|
|
||||||
|
|
||||||
if (null === $path = $input->getArgument('path')) {
|
if (null === $path = $input->getArgument('path')) {
|
||||||
$io->title(
|
$io->title(
|
||||||
|
@ -66,6 +66,14 @@ class ConfigDebugCommandTest extends WebTestCase
|
|||||||
$this->assertContains('Unable to find configuration for "test.foo"', $tester->getDisplay());
|
$this->assertContains('Unable to find configuration for "test.foo"', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDumpWithPrefixedEnv()
|
||||||
|
{
|
||||||
|
$tester = $this->createCommandTester();
|
||||||
|
$tester->execute(['name' => 'FrameworkBundle']);
|
||||||
|
|
||||||
|
$this->assertContains("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'", $tester->getDisplay());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return CommandTester
|
* @return CommandTester
|
||||||
*/
|
*/
|
||||||
|
@ -4,7 +4,10 @@ imports:
|
|||||||
framework:
|
framework:
|
||||||
secret: '%secret%'
|
secret: '%secret%'
|
||||||
default_locale: '%env(LOCALE)%'
|
default_locale: '%env(LOCALE)%'
|
||||||
|
session:
|
||||||
|
cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'
|
||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
env(LOCALE): en
|
env(LOCALE): en
|
||||||
|
env(COOKIE_HTTPONLY): '1'
|
||||||
secret: test
|
secret: test
|
||||||
|
@ -28,11 +28,15 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
|
|||||||
{
|
{
|
||||||
private static $typeFixtures = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];
|
private static $typeFixtures = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];
|
||||||
|
|
||||||
|
private $extensionConfig = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function process(ContainerBuilder $container)
|
public function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
|
$this->extensionConfig = [];
|
||||||
|
|
||||||
if (!class_exists(BaseNode::class) || !$extensions = $container->getExtensions()) {
|
if (!class_exists(BaseNode::class) || !$extensions = $container->getExtensions()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -77,7 +81,7 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$processor->processConfiguration($configuration, $config);
|
$this->extensionConfig[$name] = $processor->processConfiguration($configuration, $config);
|
||||||
} catch (TreeWithoutRootNodeException $e) {
|
} catch (TreeWithoutRootNodeException $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,6 +92,18 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
|
|||||||
$resolvingBag->clearUnusedEnvPlaceholders();
|
$resolvingBag->clearUnusedEnvPlaceholders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function getExtensionConfig(): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->extensionConfig;
|
||||||
|
} finally {
|
||||||
|
$this->extensionConfig = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static function getType($value): string
|
private static function getType($value): string
|
||||||
{
|
{
|
||||||
switch ($type = \gettype($value)) {
|
switch ($type = \gettype($value)) {
|
||||||
|
Reference in New Issue
Block a user