Skip to content

Commit

Permalink
bug #30648 Debug finalized config in debug:config (ro0NL)
Browse files Browse the repository at this point in the history
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
-------

b9ac3a5 Debug finalized config in debug:config
  • Loading branch information
fabpot committed Mar 23, 2019
2 parents 7e5dfcf + b9ac3a5 commit 2d2cd40
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php
Expand Up @@ -11,12 +11,12 @@

namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Yaml;

Expand Down Expand Up @@ -80,15 +80,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
$container = $this->compileContainer();

$extensionAlias = $extension->getAlias();
$configs = $container->getExtensionConfig($extensionAlias);
$configuration = $extension->getConfiguration($configs, $container);

$this->validateConfiguration($extension, $configuration);
$extensionConfig = [];
foreach ($container->getCompilerPassConfig()->getPasses() as $pass) {
if ($pass instanceof ValidateEnvPlaceholdersPass) {
$extensionConfig = $pass->getExtensionConfig();
break;
}
}

$configs = $container->resolveEnvPlaceholders($container->getParameterBag()->resolveValue($configs));
if (!isset($extensionConfig[$extensionAlias])) {
throw new \LogicException(sprintf('The extension with alias "%s" does not have configuration.', $extensionAlias));
}

$processor = new Processor();
$config = $container->resolveEnvPlaceholders($container->getParameterBag()->resolveValue($processor->processConfiguration($configuration, $configs)));
$config = $container->resolveEnvPlaceholders($extensionConfig[$extensionAlias]);

if (null === $path = $input->getArgument('path')) {
$io->title(
Expand Down
Expand Up @@ -66,6 +66,14 @@ public function testDumpUndefinedBundleOption()
$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
*/
Expand Down
Expand Up @@ -4,7 +4,10 @@ imports:
framework:
secret: '%secret%'
default_locale: '%env(LOCALE)%'
session:
cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'

parameters:
env(LOCALE): en
env(COOKIE_HTTPONLY): '1'
secret: test
Expand Up @@ -28,11 +28,15 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
{
private static $typeFixtures = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];

private $extensionConfig = [];

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$this->extensionConfig = [];

if (!class_exists(BaseNode::class) || !$extensions = $container->getExtensions()) {
return;
}
Expand Down Expand Up @@ -77,7 +81,7 @@ public function process(ContainerBuilder $container)
}

try {
$processor->processConfiguration($configuration, $config);
$this->extensionConfig[$name] = $processor->processConfiguration($configuration, $config);
} catch (TreeWithoutRootNodeException $e) {
}
}
Expand All @@ -88,6 +92,18 @@ public function process(ContainerBuilder $container)
$resolvingBag->clearUnusedEnvPlaceholders();
}

/**
* @internal
*/
public function getExtensionConfig(): array
{
try {
return $this->extensionConfig;
} finally {
$this->extensionConfig = [];
}
}

private static function getType($value): string
{
switch ($type = \gettype($value)) {
Expand Down

0 comments on commit 2d2cd40

Please sign in to comment.