Deprecate the special SYMFONY__ environment variables

This commit is contained in:
Javier Eguiluz 2017-03-06 10:41:30 +01:00 committed by Fabien Potencier
parent c12727deb8
commit e3362e854c
8 changed files with 54 additions and 17 deletions

View File

@ -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
-------

View File

@ -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
----

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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`

View File

@ -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;
}
}

View File

@ -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.
*