Skip to content

Commit 083e165

Browse files
[FrameworkBundle] Add resolve-env option to debug:config command
1 parent 4a3cf42 commit 083e165

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Command/ConfigDebugCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Console\Exception\LogicException;
2020
use Symfony\Component\Console\Input\InputArgument;
2121
use Symfony\Component\Console\Input\InputInterface;
22+
use Symfony\Component\Console\Input\InputOption;
2223
use Symfony\Component\Console\Output\OutputInterface;
2324
use Symfony\Component\Console\Style\SymfonyStyle;
2425
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
@@ -46,6 +47,7 @@ protected function configure()
4647
->setDefinition([
4748
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
4849
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
50+
new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Display resolved environment variable values instead of placeholders'),
4951
])
5052
->setHelp(<<<'EOF'
5153
The <info>%command.name%</info> command dumps the current configuration for an
@@ -94,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9496
$extensionAlias = $extension->getAlias();
9597
$container = $this->compileContainer();
9698

97-
$config = $this->getConfig($extension, $container);
99+
$config = $this->getConfig($extension, $container, $input->getOption('resolve-env'));
98100

99101
if (null === $path = $input->getArgument('path')) {
100102
$io->title(
@@ -210,12 +212,12 @@ private function getAvailableBundles(bool $alias): array
210212
return $availableBundles;
211213
}
212214

213-
private function getConfig(ExtensionInterface $extension, ContainerBuilder $container)
215+
private function getConfig(ExtensionInterface $extension, ContainerBuilder $container, bool $resolveEnvs = false)
214216
{
215217
return $container->resolveEnvPlaceholders(
216218
$container->getParameterBag()->resolveValue(
217219
$this->getConfigForExtension($extension, $container)
218-
)
220+
), $resolveEnvs ?: null
219221
);
220222
}
221223

Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ public function testParametersValuesAreResolved()
6060
$this->assertStringContainsString('secret: test', $tester->getDisplay());
6161
}
6262

63+
public function testParametersValuesAreFullyResolved()
64+
{
65+
$tester = $this->createCommandTester();
66+
$ret = $tester->execute(['name' => 'framework', '--resolve-env' => true]);
67+
68+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
69+
$this->assertStringContainsString('locale: en', $tester->getDisplay());
70+
$this->assertStringContainsString('secret: test', $tester->getDisplay());
71+
$this->assertStringContainsString('cookie_httponly: true', $tester->getDisplay());
72+
$this->assertStringContainsString('ide: null', $tester->getDisplay());
73+
}
74+
6375
public function testDefaultParameterValueIsResolvedIfConfigIsExisting()
6476
{
6577
$tester = $this->createCommandTester();

0 commit comments

Comments
 (0)