|
15 | 15 | use Symfony\Component\Console\Exception\LogicException;
|
16 | 16 | use Symfony\Component\Console\Input\InputArgument;
|
17 | 17 | use Symfony\Component\Console\Input\InputInterface;
|
| 18 | +use Symfony\Component\Console\Input\InputOption; |
18 | 19 | use Symfony\Component\Console\Output\OutputInterface;
|
19 | 20 | use Symfony\Component\Console\Style\SymfonyStyle;
|
20 | 21 | use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
|
@@ -44,6 +45,7 @@ protected function configure()
|
44 | 45 | ->setDefinition([
|
45 | 46 | new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
|
46 | 47 | new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
|
| 48 | + new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Resolve the value of environment variables'), |
47 | 49 | ])
|
48 | 50 | ->setDescription(self::$defaultDescription)
|
49 | 51 | ->setHelp(<<<'EOF'
|
@@ -107,6 +109,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
107 | 109 |
|
108 | 110 | $config = $container->resolveEnvPlaceholders($extensionConfig[$extensionAlias]);
|
109 | 111 |
|
| 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 | + |
110 | 123 | if (null === $path = $input->getArgument('path')) {
|
111 | 124 | $io->title(
|
112 | 125 | sprintf('Current configuration for %s', ($name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name)))
|
|
0 commit comments