From c9f2f722a1d800d9b775845993f7aeb5a7d43263 Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Tue, 13 Dec 2016 12:21:30 +0100 Subject: [PATCH 1/5] Add support for REDIS_URL environment variables. --- .../DependencyInjection/Compiler/CachePoolPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php index e4e3bc3506d82..a6078a49ee298 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php @@ -106,7 +106,7 @@ private function getNamespace($seed, $id) */ public static function getServiceProvider(ContainerBuilder $container, $name) { - if (0 === strpos($name, 'redis://')) { + if (0 === strpos($name, 'redis://') || 0 === strpos($name, '%env')) { $dsn = $name; if (!$container->hasDefinition($name = md5($dsn))) { From 7871349f3d29e05ba6c4669435bfab964b0bbc21 Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Tue, 13 Dec 2016 13:07:23 +0100 Subject: [PATCH 2/5] Correctly resolve any possible environment variables. --- .../DependencyInjection/Compiler/CachePoolPass.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php index a6078a49ee298..151386b5a4f5e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php @@ -106,7 +106,9 @@ private function getNamespace($seed, $id) */ public static function getServiceProvider(ContainerBuilder $container, $name) { - if (0 === strpos($name, 'redis://') || 0 === strpos($name, '%env')) { + $container->resolveEnvPlaceholders($name, null, $usedEnvs); + + if (0 === strpos($name, 'redis://') || $usedEnvs) { $dsn = $name; if (!$container->hasDefinition($name = md5($dsn))) { From 6f851ebdc1a102ff49b7f76664e27474b636ae71 Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Tue, 13 Dec 2016 13:15:45 +0100 Subject: [PATCH 3/5] Added test cases for the default redis provider. --- .../Fixtures/php/cache_env_var.php | 9 ++++++ .../Fixtures/xml/cache_env_var.xml | 17 +++++++++++ .../Fixtures/yml/cache_env_var.yml | 6 ++++ .../FrameworkExtensionTest.php | 28 +++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache_env_var.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache_env_var.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache_env_var.yml 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 0000000000000..b93ade8f4c816 --- /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 0000000000000..8f03cb1784b35 --- /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 0000000000000..c97ab0e6c91d7 --- /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)%" \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 940f5465187ee..e2346b4846efe 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -698,6 +698,34 @@ public function testPropertyInfoEnabled() $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'); From a230eff01c1fc1afbe3fe98778988840c5136ea4 Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Tue, 13 Dec 2016 13:34:03 +0100 Subject: [PATCH 4/5] Applied CS patch. --- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index e2346b4846efe..e4431efbc318d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -702,7 +702,7 @@ public function testCacheDefaultRedisProvider() { $container = $this->createContainerFromFile('cache'); - $redisUrl= 'redis://localhost'; + $redisUrl = 'redis://localhost'; $providerId = md5($redisUrl); $this->assertTrue($container->hasDefinition($providerId)); From c2db3e501a6171540bf5f1b6e16d8e337b43e951 Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Tue, 13 Dec 2016 13:39:40 +0100 Subject: [PATCH 5/5] Added EOL. --- .../Tests/DependencyInjection/Fixtures/yml/cache_env_var.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index c97ab0e6c91d7..1d9ce5f7f02f7 100644 --- 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 @@ -3,4 +3,4 @@ parameters: framework: cache: - default_redis_provider: "%env(REDIS_URL)%" \ No newline at end of file + default_redis_provider: "%env(REDIS_URL)%"