Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3362e8

Browse files
javiereguiluzfabpot
authored andcommitted
Deprecate the special SYMFONY__ environment variables
1 parent c12727d commit e3362e8

File tree

8 files changed

+54
-17
lines changed

8 files changed

+54
-17
lines changed

UPGRADE-3.3.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ FrameworkBundle
153153
have been deprecated and will be removed in 4.0.
154154

155155
* Extending `ConstraintValidatorFactory` is deprecated and won't be supported in 4.0.
156-
156+
157157
* Class parameters related to routing have been deprecated and will be removed in 4.0.
158158
* router.options.generator_class
159159
* router.options.generator_base_class
@@ -168,8 +168,8 @@ FrameworkBundle
168168
has been deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass`
169169
class instead.
170170

171-
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass`
172-
class has been deprecated and will be removed in 4.0. Use the
171+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass`
172+
class has been deprecated and will be removed in 4.0. Use the
173173
`Symfony\Component\Routing\DependencyInjection\RoutingResolverPass` class instead.
174174

175175
HttpKernel
@@ -187,6 +187,13 @@ HttpKernel
187187
which will tell the Kernel to use the response code set on the event's
188188
response object.
189189

190+
* The `Kernel::getEnvParameters()` method has been deprecated and will be
191+
removed in 4.0.
192+
193+
* The `SYMFONY__` environment variables have been deprecated and they will be
194+
no longer processed automatically by Symfony in 4.0. Use the `%env()%` syntax
195+
to get the value of any environment variable from configuration files instead.
196+
190197
Process
191198
-------
192199

UPGRADE-4.0.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ FrameworkBundle
268268
class instead.
269269

270270
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass`
271-
class has been removed. Use the
271+
class has been removed. Use the
272272
`Symfony\Component\Routing\DependencyInjection\RoutingResolverPass` class instead.
273273

274274
HttpFoundation
@@ -321,6 +321,12 @@ HttpKernel
321321
which will tell the Kernel to use the response code set on the event's
322322
response object.
323323

324+
* The `Kernel::getEnvParameters()` method has been removed.
325+
326+
* The `SYMFONY__` environment variables are no longer processed automatically
327+
by Symfony. Use the `%env()%` syntax to get the value of any environment
328+
variable from configuration files instead.
329+
324330
Ldap
325331
----
326332

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@
1717

1818
class CachePoolsTest extends WebTestCase
1919
{
20-
protected function setUp()
21-
{
22-
$_SERVER['SYMFONY__REDIS_HOST'] = getenv('REDIS_HOST');
23-
}
24-
25-
protected function tearDown()
26-
{
27-
unset($_SERVER['SYMFONY__REDIS_HOST']);
28-
}
29-
3020
public function testCachePools()
3121
{
3222
$this->doTestCachePools(array(), FilesystemAdapter::class);

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
imports:
22
- { resource: ../config/default.yml }
33

4+
parameters:
5+
env(REDIS_HOST): 'localhost'
6+
47
framework:
58
cache:
69
app: cache.adapter.redis
7-
default_redis_provider: "redis://%redis_host%"
10+
default_redis_provider: "redis://%env(REDIS_HOST)%"
811
pools:
912
cache.pool1:
1013
public: true

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_custom_config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
imports:
22
- { resource: ../config/default.yml }
33

4+
parameters:
5+
env(REDIS_HOST): 'localhost'
6+
47
services:
58
cache.test_redis_connection:
69
public: false
710
class: Redis
811
calls:
9-
- [connect, ['%redis_host%']]
12+
- [connect, ['%env(REDIS_HOST)%']]
1013

1114
cache.app:
1215
parent: cache.adapter.redis

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
3.3.0
55
-----
66

7+
* Deprecated `Kernel::getEnvParameters()`
8+
* Deprecated the special `SYMFONY__` environment variables
79
* added the possibility to change the query string parameter used by `UriSigner`
810
* deprecated `LazyLoadingFragmentHandler::addRendererService()`
911
* added `SessionListener`

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ protected function getKernelParameters()
563563
'kernel.charset' => $this->getCharset(),
564564
'kernel.container_class' => $this->getContainerClass(),
565565
),
566-
$this->getEnvParameters()
566+
$this->getEnvParameters(false)
567567
);
568568
}
569569

@@ -573,12 +573,19 @@ protected function getKernelParameters()
573573
* Only the parameters starting with "SYMFONY__" are considered.
574574
*
575575
* @return array An array of parameters
576+
*
577+
* @deprecated since version 3.3, to be removed in 4.0
576578
*/
577579
protected function getEnvParameters()
578580
{
581+
if (0 === func_num_args() || func_get_arg(0)) {
582+
@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);
583+
}
584+
579585
$parameters = array();
580586
foreach ($_SERVER as $key => $value) {
581587
if (0 === strpos($key, 'SYMFONY__')) {
588+
@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);
582589
$parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
583590
}
584591
}

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,25 @@ public function testKernelRootDirNameStartingWithANumber()
742742
$this->assertEquals('_123', $kernel->getName());
743743
}
744744

745+
/**
746+
* @group legacy
747+
* @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.
748+
* @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.
749+
*/
750+
public function testSymfonyEnvironmentVariables()
751+
{
752+
$_SERVER['SYMFONY__FOO__BAR'] = 'baz';
753+
754+
$kernel = $this->getKernel();
755+
$method = new \ReflectionMethod($kernel, 'getEnvParameters');
756+
$method->setAccessible(true);
757+
758+
$envParameters = $method->invoke($kernel);
759+
$this->assertSame('baz', $envParameters['foo.bar']);
760+
761+
unset($_SERVER['SYMFONY__FOO__BAR']);
762+
}
763+
745764
/**
746765
* Returns a mock for the BundleInterface.
747766
*

0 commit comments

Comments
 (0)