diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php index 22811c655889..17571fb48ad2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->validateConfiguration($extension, $configuration); - $configs = $container->getParameterBag()->resolveValue($configs); + $configs = $container->resolveEnvPlaceholders($container->getParameterBag()->resolveValue($configs)); $processor = new Processor(); $config = $processor->processConfiguration($configuration, $configs); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 981df241cd3a..c9d0e419e290 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -19,6 +19,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\Config\FileLocator; /** @@ -96,7 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $object = $this->getContainerBuilder(); if ($input->getOption('parameters')) { - $object = $object->getParameterBag(); + $parameters = array(); + foreach ($object->getParameterBag()->all() as $k => $v) { + $parameters[$k] = $object->resolveEnvPlaceholders($v); + } + $object = new ParameterBag($parameters); $options = array(); } elseif ($parameter = $input->getOption('parameter')) { $options = array('parameter' => $parameter); diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index da809aea8df6..95c932466249 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -57,7 +57,7 @@ public function describe(OutputInterface $output, $object, array $options = arra $this->describeContainerService($this->resolveServiceDefinition($object, $options['id']), $options); break; case $object instanceof ContainerBuilder && isset($options['parameter']): - $this->describeContainerParameter($object->getParameter($options['parameter']), $options); + $this->describeContainerParameter($object->resolveEnvPlaceholders($object->getParameter($options['parameter'])), $options); break; case $object instanceof ContainerBuilder: $this->describeContainerServices($object, $options); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 58a38048f753..45c6f2cf677b 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -1026,34 +1026,47 @@ public function getExpressionLanguageProviders() } /** - * Resolves env parameter placeholders in a string. + * Resolves env parameter placeholders in a string or an array. * - * @param string $string The string to resolve + * @param mixed $value The value to resolve * @param string|null $format A sprintf() format to use as replacement for env placeholders or null to use the default parameter format * @param array &$usedEnvs Env vars found while resolving are added to this array * * @return string The string with env parameters resolved */ - public function resolveEnvPlaceholders($string, $format = null, array &$usedEnvs = null) + public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs = null) { - $bag = $this->getParameterBag(); - $envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders; - if (null === $format) { $format = '%%env(%s)%%'; } + if (is_array($value)) { + $result = array(); + foreach ($value as $k => $v) { + $result[$this->resolveEnvPlaceholders($k, $format, $usedEnvs)] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs); + } + + return $result; + } + + if (!is_string($value)) { + return $value; + } + + $bag = $this->getParameterBag(); + $envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders; + foreach ($envPlaceholders as $env => $placeholders) { foreach ($placeholders as $placeholder) { - if (false !== stripos($string, $placeholder)) { - $string = str_ireplace($placeholder, sprintf($format, $env), $string); + if (false !== stripos($value, $placeholder)) { + $value = str_ireplace($placeholder, sprintf($format, $env), $value); $usedEnvs[$env] = $env; $this->envCounters[$env] = isset($this->envCounters[$env]) ? 1 + $this->envCounters[$env] : 1; } } } - return $string; + return $value; } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 155da75fb795..9ba5a36c4d55 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -495,7 +495,7 @@ public function testMerge() $bag = new EnvPlaceholderParameterBag(); $bag->get('env(Foo)'); $config = new ContainerBuilder($bag); - $config->resolveEnvPlaceholders($bag->get('env(Bar)')); + $this->assertSame(array('%env(Bar)%'), $config->resolveEnvPlaceholders(array($bag->get('env(Bar)')))); $container->merge($config); $this->assertEquals(array('Foo' => 0, 'Bar' => 1), $container->getEnvCounters()); }