diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 68aad4a6a74c1..e6249e49e6c06 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1241,6 +1241,10 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con if (isset($config['prefix_seed'])) { $container->setParameter('cache.prefix.seed', $config['prefix_seed']); } + if ($container->hasParameter('cache.prefix.seed')) { + // Inline any env vars referenced in the parameter + $container->setParameter('cache.prefix.seed', $container->resolveEnvPlaceholders($container->getParameter('cache.prefix.seed'), true)); + } foreach (array('doctrine', 'psr6', 'redis') as $name) { if (isset($config[$name = 'default_'.$name.'_provider'])) { $container->setAlias('cache.'.$name, new Alias(Compiler\CachePoolPass::getServiceProvider($container, $config[$name]), false)); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 45c6f2cf677b0..f0898408d6912 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -1028,9 +1028,11 @@ public function getExpressionLanguageProviders() /** * Resolves env parameter placeholders in a string or an array. * - * @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 + * @param mixed $value The value to resolve + * @param string|true|null $format A sprintf() format returning the replacement for each env var name or + * null to resolve back to the original "%env(VAR)%" format or + * true to resolve to the actual values of the referenced env vars + * @param array &$usedEnvs Env vars found while resolving are added to this array * * @return string The string with env parameters resolved */ @@ -1054,12 +1056,20 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs } $bag = $this->getParameterBag(); + if (true === $format) { + $value = $bag->resolveValue($value); + } $envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders; foreach ($envPlaceholders as $env => $placeholders) { foreach ($placeholders as $placeholder) { if (false !== stripos($value, $placeholder)) { - $value = str_ireplace($placeholder, sprintf($format, $env), $value); + if (true === $format) { + $resolved = $bag->escapeValue($this->getEnv($env)); + } else { + $resolved = sprintf($format, $env); + } + $value = str_ireplace($placeholder, $resolved, $value); $usedEnvs[$env] = $env; $this->envCounters[$env] = isset($this->envCounters[$env]) ? 1 + $this->envCounters[$env] : 1; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 9ba5a36c4d55d..7e495297267da 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -500,6 +500,18 @@ public function testMerge() $this->assertEquals(array('Foo' => 0, 'Bar' => 1), $container->getEnvCounters()); } + public function testResolveEnvValues() + { + $_ENV['DUMMY_ENV_VAR'] = 'du%%y'; + + $container = new ContainerBuilder(); + $container->setParameter('bar', '%% %env(DUMMY_ENV_VAR)%'); + + $this->assertSame('%% du%%%%y', $container->resolveEnvPlaceholders('%bar%', true)); + + unset($_ENV['DUMMY_ENV_VAR']); + } + /** * @expectedException \LogicException */