-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Conversation
javiereguiluz
commented
Mar 6, 2017
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 | - |
I surely miss something but #20100 (comment):
Or do we plan to trigger this deprecation forever? |
Vastly prefer the implementation described in #20100 (comment). I was going to comment on this earlier, but couldn't find that comment by @chalasr. |
@chalasr about your comment, I don't agree on reporting the deprecation when using the env var instead of when setting it (if you set it, it's because you have defined it ... so you should get the deprecation). About the other proposal ... I don't know what to say ... but others think it's much better, so if you can implement it, I guess we can close this PR in favor of your PR. Thanks! |
The reason I believe we shouldn't get any deprecations until an environment variable is actually used is because otherwise, we are restricting the use of external environment variables without knowing that they are intended for consumption by Symfony itself. People may well be using environment variables beginning with |
@javiereguiluz My point is mainly what @robfrawley said in the previous comment, but also that deprecating |
@chalasr yes, I agree that both of you are right and your solution is better than mine :) Thanks for providing the alternative PR. I'll close this one then. |
In think this implem here is right, but misses the deprecation of The alternative proposed in #21997 looks worse to me because it breaks SRP. Until someone finds another solution freed from any of the identified drawbacks, I'm 👍 here (I won't be the one working on this as the identified drawback of this PR doesn't look that realistic to me.) |
@@ -576,6 +576,7 @@ protected function getEnvParameters() | |||
$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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%env()%
should be %%env()%%
For the record, I still think that comments from Rob and Robin are right ... but I'll update this PR in case we don't find a viable alternative solution. |
Reopening, this looks like the correct approach to me:
|
If not used as a parameter then there is no reason to expect the env var to be taken into account. I don't understand how this is a better approach regarding DX, but let's move on. |
@chalasr since these env vars are used as default values, they can very well be defined by the env just in case - but actually not being used because the param is defined / not used by the current app. |
@@ -735,6 +735,23 @@ public function testKernelWithoutBundles() | |||
} | |||
|
|||
/** | |||
* @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 %s 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 %env()% syntax instead to get the value of environment variables in configuration files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of %env()%
makes the assertion fails due to the use of assertStringMatchesFormat
. For now I didn't find better than replacing %env()%
by %s
in the expected deprecation to solve this issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%c
is a bit better :)
$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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 :)
missing entries in CHANGELOG / UPGRADE files |
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments, a rebase, and a test fix, then all good on my side.
UPGRADE-3.3.md
Outdated
@@ -181,6 +181,12 @@ HttpKernel | |||
which will tell the Kernel to use the response code set on the event's | |||
response object. | |||
|
|||
* The `getEnvParameters()` method has been deprecated and will be removed in 4.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kernel::getEnvParameters()
UPGRADE-4.0.md
Outdated
@@ -321,6 +321,12 @@ HttpKernel | |||
which will tell the Kernel to use the response code set on the event's | |||
response object. | |||
|
|||
* The `getEnvParameters()` method has been removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kernel::getEnvParameters()
@@ -7,6 +7,8 @@ CHANGELOG | |||
* Deprecated `LazyLoadingFragmentHandler::addRendererService()` | |||
* Added `SessionListener` | |||
* Added `TestSessionListener` | |||
* Deprecated `getEnvParameters` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kernel::getEnvParameters()
3482860
to
924e18c
Compare
@@ -19,12 +19,12 @@ class CachePoolsTest extends WebTestCase | |||
{ | |||
protected function setUp() | |||
{ | |||
$_SERVER['SYMFONY__REDIS_HOST'] = getenv('REDIS_HOST'); | |||
$_SERVER['REDIS_HOST'] = getenv('REDIS_HOST'); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure. Can I remove both setUp() and tearDown() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say yes
Tests are broken. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
The last failing tests seem unrelated, so this is now ready! A big "thank you" to @chalasr for his great help fixing all the failing tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you @javiereguiluz. |
The special SYMFONY__ environment variables have been deprecated in Symfony 3.3 (and will be removed in 4.0) as there is now support for runtime environment variables in Symfony. This commit allows for different environment variables to be used as the first step in removing the old variables. A later step should remove the `parameters.yml` file entirely and have the configuration be solely from passed environment variables (or .env file for development). ref: [Deprecation blog post](https://symfony.com/blog/new-in-symfony-3-3-deprecated-the-special-symfony-environment-variables) ref: symfony/symfony#21889