diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php index 1e09b88214..df02d65259 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php @@ -96,7 +96,9 @@ class CachePoolPass implements CompilerPassInterface */ public static function getServiceProvider(ContainerBuilder $container, $name) { - if (0 === strpos($name, 'redis://')) { + $container->resolveEnvPlaceholders($name, null, $usedEnvs); + + if (0 === strpos($name, 'redis://') || $usedEnvs) { $dsn = $name; if (!$container->hasDefinition($name = md5($dsn))) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache_env_var.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache_env_var.php new file mode 100644 index 0000000000..b93ade8f4c --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache_env_var.php @@ -0,0 +1,9 @@ +setParameter('env(REDIS_URL)', 'redis://paas.com'); + +$container->loadFromExtension('framework', array( + 'cache' => array( + 'default_redis_provider' => '%env(REDIS_URL)%', + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache_env_var.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache_env_var.xml new file mode 100644 index 0000000000..8f03cb1784 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache_env_var.xml @@ -0,0 +1,17 @@ + + + + + redis://paas.com + + + + + %env(REDIS_URL)% + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache_env_var.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache_env_var.yml new file mode 100644 index 0000000000..1d9ce5f7f0 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache_env_var.yml @@ -0,0 +1,6 @@ +parameters: + env(REDIS_URL): redis://paas.com + +framework: + cache: + default_redis_provider: "%env(REDIS_URL)%" diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 4388b70afe..26792c6b1c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -697,6 +697,34 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertTrue($container->has('property_info')); } + public function testCacheDefaultRedisProvider() + { + $container = $this->createContainerFromFile('cache'); + + $redisUrl = 'redis://localhost'; + $providerId = md5($redisUrl); + + $this->assertTrue($container->hasDefinition($providerId)); + + $url = $container->getDefinition($providerId)->getArgument(0); + + $this->assertSame($redisUrl, $url); + } + + public function testCacheDefaultRedisProviderWithEnvVar() + { + $container = $this->createContainerFromFile('cache_env_var'); + + $redisUrl = 'redis://paas.com'; + $providerId = md5($redisUrl); + + $this->assertTrue($container->hasDefinition($providerId)); + + $url = $container->getDefinition($providerId)->getArgument(0); + + $this->assertSame($redisUrl, $url); + } + public function testCachePoolServices() { $container = $this->createContainerFromFile('cache');