8000 [FrameworkBundle] Resolve env params in debug:config command · symfony/symfony@695d100 · GitHub
[go: up one dir, main page]

Skip to content

Commit 695d100

Browse files
[FrameworkBundle] Resolve env params in debug:config command
1 parent bd5af67 commit 695d100

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080

8181
$this->validateConfiguration($extension, $configuration);
8282

83-
$configs = $container->getParameterBag()->resolveValue($configs);
83+
$configs = $container->resolveEnvPlaceholders($container->getParameterBag()->resolveValue($configs));
8484

8585
$processor = new Processor();
8686
$config = $processor->processConfiguration($configuration, $configs);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Console\Style\SymfonyStyle;
2020
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2121
use Symfony\Component\DependencyInjection\ContainerBuilder;
22+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2223
use Symfony\Component\Config\FileLocator;
2324

2425
/**
@@ -96,7 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
9697
$object = $this->getContainerBuilder();
9798

9899
if ($input->getOption('parameters')) {
99-
$object = $object->getParameterBag();
100+
$parameters = array();
101+
foreach ($object->getParameterBag()->all() as $k => $v) {
102+
$parameters[$k] = $object->resolveEnvPlaceholders($v);
103+
}
104+
$object = new ParameterBag($parameters);
100105
$options = array();
101106
} elseif ($parameter = $input->getOption('parameter')) {
102107
$options = array('parameter' => $parameter);

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function describe(OutputInterface $output, $object, array $options = arra
5757
$this->describeContainerService($this->resolveServiceDefinition($object, $options['id']), $options);
5858
break;
5959
case $object instanceof ContainerBuilder && isset($options['parameter']):
60-
$this->describeContainerParameter($object->getParameter($options['parameter']), $options);
60+
$this->describeContainerParameter($object->resolveEnvPlaceholders($object->getParameter($options['parameter'])), $options);
6161
break;
6262
case $object instanceof ContainerBuilder:
6363
$this->describeContainerServices($object, $options);

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,34 +1026,47 @@ public function getExpressionLanguageProviders()
10261026
}
10271027

10281028
/**
1029-
* Resolves env parameter placeholders in a string.
1029+
* Resolves env parameter placeholders in a string or an array.
10301030
*
1031-
* @param string $string The string to resolve
1031+
* @param mixed $value The value to resolve
10321032
* @param string|null $format A sprintf() format to use as replacement for env placeholders or null to use the default parameter format
10331033
* @param array &$usedEnvs Env vars found while resolving are added to this array
10341034
*
10351035
* @return string The string with env parameters resolved
10361036
*/
1037-
public function resolveEnvPlaceholders($string, $format = null, array &$usedEnvs = null)
1037+
public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs = null)
10381038
{
1039-
$bag = $this->getParameterBag();
1040-
$envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders;
1041-
10421039
if (null === $format) {
10431040
$format = '%%env(%s)%%';
10441041
}
10451042

1043+
if (is_array($value)) {
1044+
$result = array();
1045+
foreach ($value as $k => $v) {
1046+
$result[$this->resolveEnvPlaceholders($k, $format, $usedEnvs)] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs);
1047+
}
1048+
1049+
return $result;
1050+
}
1051+
1052+
if (!is_string($value)) {
1053+
return $value;
1054+
}
1055+
1056+
$bag = $this->getParameterBag();
1057+
$envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders;
1058+
10461059
foreach ($envPlaceholders as $env => $placeholders) {
10471060
foreach ($placeholders as $placeholder) {
1048-
if (false !== stripos($string, $placeholder)) {
1049-
$string = str_ireplace($placeholder, sprintf($format, $env), $string);
1061+
if (false !== stripos($value, $placeholder)) {
1062+
$value = str_ireplace($placeholder, sprintf($format, $env), $value);
10501063
$usedEnvs[$env] = $env;
10511064
$this->envCounters[$env] = isset($this->envCounters[$env]) ? 1 + $this->envCounters[$env] : 1;
10521065
}
10531066
}
10541067
}
10551068

1056-
return $string;
1069+
return $value;
10571070
}
10581071

10591072
/**

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public function testMerge()
495495
$bag = new EnvPlaceholderParameterBag();
496496
$bag->get('env(Foo)');
497497
$config = new ContainerBuilder($bag);
498-
$config->resolveEnvPlaceholders($bag->get('env(Bar)'));
498+
$this->assertSame(array('%env(Bar)%'), $config->resolveEnvPlaceholders(array($bag->get('env(Bar)'))));
499499
$container->merge($config);
500500
$this->assertEquals(array('Foo' => 0, 'Bar' => 1), $container->getEnvCounters());
501501
}

0 commit comments

Comments
 (0)
0