Skip to content

Commit

Permalink
feature #21889 Deprecate the special SYMFONY__ environment variables …
Browse files Browse the repository at this point in the history
…(javiereguiluz)

This PR was squashed before being merged into the 3.3-dev branch (closes #21889).

Discussion
----------

Deprecate the special SYMFONY__ environment variables

| Q | A |
| --- | --- |
| Branch? | master |
| Bug fix? | no |
| New feature? | no |
| BC breaks? | no |
| Deprecations? | yes |
| Tests pass? | yes |
| Fixed tickets | #20089 |
| License | MIT |
| Doc PR | - |

Commits
-------

e3362e8 Deprecate the special SYMFONY__ environment variables
  • Loading branch information
fabpot committed Mar 21, 2017
2 parents 7f89ad4 + e3362e8 commit a96a997
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 17 deletions.
13 changes: 10 additions & 3 deletions UPGRADE-3.3.md
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.

* The `server:run`, `server:start`, `server:stop` and
Expand All @@ -192,6 +192,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
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
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
@@ -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
@@ -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
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
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);
$parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
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

0 comments on commit a96a997

Please sign in to comment.