Skip to content

Deprecate the special SYMFONY__ environment variables #21889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
13 changes: 10 additions & 3 deletions UPGRADE-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
-------

Expand Down
8 changes: 7 additions & 1 deletion UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
9 changes: 8 additions & 1 deletion src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ protected function getKernelParameters()
'kernel.charset' => $this->getCharset(),
'kernel.container_class' => $this->getContainerClass(),
),
$this->getEnvParameters()
$this->getEnvParameters(false)
);
}

Expand All @@ -573,12 +573,19 @@ protected function getKernelParameters()
* 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not great but we have to exclude the special env vars which are set from the core: SYMFONY__REDIS_HOST is one (https://travis-ci.org/symfony/symfony/jobs/211006453)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or not use it anymore :)

$parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,25 @@ public function testKernelRootDirNameStartingWithANumber()
$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.
*
Expand Down