From bdc8e0224c5f377f4da5beb2019ba908c145219b Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Fri, 1 Jul 2022 09:05:37 +0200 Subject: [PATCH] [FrameworkBundle] Add `resolve-env` option to debug:config command --- .../FrameworkBundle/Command/ConfigDebugCommand.php | 8 +++++--- .../Tests/Functional/ConfigDebugCommandTest.php | 12 ++++++++++++ .../Component/DependencyInjection/CHANGELOG.md | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php index b2557be7b0e2d..8104f62a796c1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -19,6 +19,7 @@ use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass; @@ -46,6 +47,7 @@ protected function configure() ->setDefinition([ new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'), new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'), + new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Display resolved environment variable values instead of placeholders'), ]) ->setHelp(<<<'EOF' The %command.name% command dumps the current configuration for an @@ -94,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $extensionAlias = $extension->getAlias(); $container = $this->compileContainer(); - $config = $this->getConfig($extension, $container); + $config = $this->getConfig($extension, $container, $input->getOption('resolve-env')); if (null === $path = $input->getArgument('path')) { $io->title( @@ -210,12 +212,12 @@ private function getAvailableBundles(bool $alias): array return $availableBundles; } - private function getConfig(ExtensionInterface $extension, ContainerBuilder $container) + private function getConfig(ExtensionInterface $extension, ContainerBuilder $container, bool $resolveEnvs = false) { return $container->resolveEnvPlaceholders( $container->getParameterBag()->resolveValue( $this->getConfigForExtension($extension, $container) - ) + ), $resolveEnvs ?: null ); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php index 463318af39f47..09b99f82f7c64 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php @@ -60,6 +60,18 @@ public function testParametersValuesAreResolved() $this->assertStringContainsString('secret: test', $tester->getDisplay()); } + public function testParametersValuesAreFullyResolved() + { + $tester = $this->createCommandTester(); + $ret = $tester->execute(['name' => 'framework', '--resolve-env' => true]); + + $this->assertSame(0, $ret, 'Returns 0 in case of success'); + $this->assertStringContainsString('locale: en', $tester->getDisplay()); + $this->assertStringContainsString('secret: test', $tester->getDisplay()); + $this->assertStringContainsString('cookie_httponly: true', $tester->getDisplay()); + $this->assertStringContainsString('ide: null', $tester->getDisplay()); + } + public function testDefaultParameterValueIsResolvedIfConfigIsExisting() { $tester = $this->createCommandTester(); diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index f9070abbfbabf..01330f55907d2 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * Add argument `&$asGhostObject` to LazyProxy's `DumperInterface` to allow using ghost objects for lazy loading services * Add `enum` env var processor * Add `shuffle` env var processor + * Add `resolve-env` option to `debug:config` command to display actual values of environment variables in dumped configuration 6.1 ---