Debug finalized config in debug:config

This commit is contained in:
Roland Franssen 2019-03-22 15:52:33 +01:00
parent 7e5dfcff7b
commit b9ac3a52fb
4 changed files with 40 additions and 9 deletions

View File

@ -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(

View File

@ -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
*/ */

View File

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

View File

@ -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)) {