8000 [FrameworkBundle] [Console] Added resolve-env option to debug:config … · symfony/symfony@dddbe3f · GitHub
[go: up one dir, main page]

Skip to content

Commit dddbe3f

Browse files
[FrameworkBundle] [Console] Added resolve-env option to debug:config command
This option replaces environment variables placeholders by their actual value in the command output
1 parent bb1e1e5 commit dddbe3f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CHANGELOG
1919
* Add `KernelTestCase::getContainer()` as the best way to get a container in tests
2020
* Rename the container parameter `profiler_listener.only_master_requests` to `profiler_listener.only_main_requests`
2121
* Add service `fragment.uri_generator` to generate the URI of a fragment
22+
* Add `--resolve-env` option to `debug:config` command to resolve the value of environment variables in the command output
2223

2324
5.2.0
2425
-----

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Exception\LogicException;
1616
use Symfony\Component\Console\Input\InputArgument;
1717
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920
use Symfony\Component\Console\Style\SymfonyStyle;
2021
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
@@ -44,6 +45,7 @@ protected function configure()
4445
->setDefinition([
4546
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
4647
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
48+
new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Resolve the value of environment variables'),
4749
])
4850
->setDescription(self::$defaultDescription)
4951
->setHelp(<<<'EOF'
@@ -107,6 +109,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
107109

108110
$config = $container->resolveEnvPlaceholders($extensionConfig[$extensionAlias]);
109111

112+
if ($input->getOption('resolve-env')) {
113+
array_walk_recursive($config, function (&$value) {
114+
preg_match_all('{%env\(((?:\w++:)*+\w++)\)%}', $value, $envVars);
115+
$name = current($envVars[1]);
116+
117+
if ($name) {
118+
$value = $_ENV[$name] ?? $_SERVER[$name] ?? getenv($name);
119+
}
120+
});
121+
}
122+
110123
if (null === $path = $input->getArgument('path')) {
111124
$io->title(
112125
sprintf('Current configuration for %s', ($name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name)))

0 commit comments

Comments
 (0)
0