From e3362e854c2de08108724467853bbad3be9f7c89 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 6 Mar 2017 10:41:30 +0100 Subject: [PATCH] Deprecate the special SYMFONY__ environment variables --- UPGRADE-3.3.md | 13 ++++++++++--- UPGRADE-4.0.md | 8 +++++++- .../Tests/Functional/CachePoolsTest.php | 10 ---------- .../app/CachePools/redis_config.yml | 5 ++++- .../app/CachePools/redis_custom_config.yml | 5 ++++- src/Symfony/Component/HttpKernel/CHANGELOG.md | 2 ++ src/Symfony/Component/HttpKernel/Kernel.php | 9 ++++++++- .../Component/HttpKernel/Tests/KernelTest.php | 19 +++++++++++++++++++ 8 files changed, 54 insertions(+), 17 deletions(-) diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index 036ad1f61c..4893bfa21d 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -153,7 +153,7 @@ FrameworkBundle have been deprecated and will be removed in 4.0. * Extending `ConstraintValidatorFactory` is deprecated and won't be supported in 4.0. - + * Class parameters related to routing have been deprecated and will be removed in 4.0. * router.options.generator_class * router.options.generator_base_class @@ -168,8 +168,8 @@ FrameworkBundle has been deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass` class instead. - * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass` - class has been deprecated and will be removed in 4.0. Use the + * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass` + class has been deprecated and will be removed in 4.0. Use the `Symfony\Component\Routing\DependencyInjection\RoutingResolverPass` class instead. HttpKernel @@ -187,6 +187,13 @@ HttpKernel which will tell the Kernel to use the response code set on the event's response object. + * The `Kernel::getEnvParameters()` method has been deprecated and will be + removed in 4.0. + + * The `SYMFONY__` environment variables have been deprecated and they will be + no longer processed automatically by Symfony in 4.0. Use the `%env()%` syntax + to get the value of any environment variable from configuration files instead. + Process ------- diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 1123d9a87a..a2dda7932d 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -268,7 +268,7 @@ FrameworkBundle class instead. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass` - class has been removed. Use the + class has been removed. Use the `Symfony\Component\Routing\DependencyInjection\RoutingResolverPass` class instead. HttpFoundation @@ -321,6 +321,12 @@ HttpKernel which will tell the Kernel to use the response code set on the event's response object. + * The `Kernel::getEnvParameters()` method has been removed. + + * The `SYMFONY__` environment variables are no longer processed automatically + by Symfony. Use the `%env()%` syntax to get the value of any environment + variable from configuration files instead. + Ldap ---- diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php index 7518cf4242..06ed75d64d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php @@ -17,16 +17,6 @@ use Symfony\Component\Cache\Exception\InvalidArgumentException; class CachePoolsTest extends WebTestCase { - protected function setUp() - { - $_SERVER['SYMFONY__REDIS_HOST'] = getenv('REDIS_HOST'); - } - - protected function tearDown() - { - unset($_SERVER['SYMFONY__REDIS_HOST']); - } - public function testCachePools() { $this->doTestCachePools(array(), FilesystemAdapter::class); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_config.yml index 2794a72c80..02de40c5b8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_config.yml @@ -1,10 +1,13 @@ imports: - { resource: ../config/default.yml } +parameters: + env(REDIS_HOST): 'localhost' + framework: cache: app: cache.adapter.redis - default_redis_provider: "redis://%redis_host%" + default_redis_provider: "redis://%env(REDIS_HOST)%" pools: cache.pool1: public: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_custom_config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_custom_config.yml index 70a51b272e..9206638495 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_custom_config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_custom_config.yml @@ -1,12 +1,15 @@ imports: - { resource: ../config/default.yml } +parameters: + env(REDIS_HOST): 'localhost' + services: cache.test_redis_connection: public: false class: Redis calls: - - [connect, ['%redis_host%']] + - [connect, ['%env(REDIS_HOST)%']] cache.app: parent: cache.adapter.redis diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 735a0b0436..146f73e6cf 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -4,6 +4,8 @@ CHANGELOG 3.3.0 ----- + * Deprecated `Kernel::getEnvParameters()` + * Deprecated the special `SYMFONY__` environment variables * added the possibility to change the query string parameter used by `UriSigner` * deprecated `LazyLoadingFragmentHandler::addRendererService()` * added `SessionListener` diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index b268f2850d..6236fcef8b 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -563,7 +563,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface 'kernel.charset' => $this->getCharset(), 'kernel.container_class' => $this->getContainerClass(), ), - $this->getEnvParameters() + $this->getEnvParameters(false) ); } @@ -573,12 +573,19 @@ abstract class Kernel implements KernelInterface, TerminableInterface * Only the parameters starting with "SYMFONY__" are considered. * * @return array An array of parameters + * + * @deprecated since version 3.3, to be removed in 4.0 */ protected function getEnvParameters() { + if (0 === func_num_args() || func_get_arg(0)) { + @trigger_error(sprintf('The %s() method is deprecated as of 3.3 and will be removed in 4.0. Use the %%env()%% syntax to get the value of any environment variable from configuration files instead.', __METHOD__), E_USER_DEPRECATED); + } + $parameters = array(); foreach ($_SERVER as $key => $value) { if (0 === strpos($key, 'SYMFONY__')) { + @trigger_error(sprintf('The support of special environment variables that start with SYMFONY__ (such as "%s") is deprecated as of 3.3 and will be removed in 4.0. Use the %%env()%% syntax instead to get the value of environment variables in configuration files.', $key), E_USER_DEPRECATED); $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value; } } diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index ea34365d59..4cc31d4990 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -742,6 +742,25 @@ EOF; $this->assertEquals('_123', $kernel->getName()); } + /** + * @group legacy + * @expectedDeprecation The Symfony\Component\HttpKernel\Kernel::getEnvParameters() method is deprecated as of 3.3 and will be removed in 4.0. Use the %cenv()%c syntax to get the value of any environment variable from configuration files instead. + * @expectedDeprecation The support of special environment variables that start with SYMFONY__ (such as "SYMFONY__FOO__BAR") is deprecated as of 3.3 and will be removed in 4.0. Use the %cenv()%c syntax instead to get the value of environment variables in configuration files. + */ + public function testSymfonyEnvironmentVariables() + { + $_SERVER['SYMFONY__FOO__BAR'] = 'baz'; + + $kernel = $this->getKernel(); + $method = new \ReflectionMethod($kernel, 'getEnvParameters'); + $method->setAccessible(true); + + $envParameters = $method->invoke($kernel); + $this->assertSame('baz', $envParameters['foo.bar']); + + unset($_SERVER['SYMFONY__FOO__BAR']); + } + /** * Returns a mock for the BundleInterface. *