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

Conversation

javiereguiluz
Copy link
Member

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 -

@chalasr
Copy link
Member

chalasr commented Mar 6, 2017

I surely miss something but #20100 (comment):

shouldn't the Kernel::getEnvParameters() method be deprecated?

Or do we plan to trigger this deprecation forever?

@robfrawley
Copy link
Contributor

Vastly prefer the implementation described in #20100 (comment). I was going to comment on this earlier, but couldn't find that comment by @chalasr.

@javiereguiluz
Copy link
Member Author

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

@robfrawley
Copy link
Contributor

robfrawley commented Mar 12, 2017

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 SYMFONY__ for their own container port mapping or other functionality related to setting up their Symfony environment, but external to the Symfony runtime itself.

@chalasr
Copy link
Member

chalasr commented Mar 14, 2017

@javiereguiluz My point is mainly what @robfrawley said in the previous comment, but also that deprecating SYMFONY__ prefixed env vars does not make sense to me in term of upgrade.
Defining these prefixed env vars will not stop to work, only using them as parameters will.
The symfony-specific behavior is only to consider these vars differently, I think the deprecation should reflect this and that this behavior should really die in 4.0 (i.e. Kernel::getEnvParameters() be removed).
I'll propose the alternative PR.

@javiereguiluz
Copy link
Member Author

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

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Mar 14, 2017

In think this implem here is right, but misses the deprecation of Kernel::getEnvParameters
The false positive that has been identified makes no harm at all: it's mainly theoretical, and it's not like it's going to break anything (4.0 won't throw - it'll just ignore and not warn anymore).

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;
Copy link
Member

@chalasr chalasr Mar 14, 2017

Choose a reason for hiding this comment

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

%env()% should be %%env()%%

@javiereguiluz
Copy link
Member Author

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.

@nicolas-grekas
Copy link
Member

Reopening, this looks like the correct approach to me:

Defining these prefixed env vars will not stop to work, only using them as parameters will.

SYMFONY__ is not a common prefix. I'd better consider that we can claim triggering a deprecation notice here. In terms of DX, it's also way more important to me to warn users that if they expect a SYMFONY__ env var to be taken into account, then that won't happen in 4.0, even in the case they don't actually use it as params.

@chalasr
Copy link
Member

chalasr commented Mar 14, 2017

even in the case they don't actually use it as params.

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.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Mar 14, 2017

@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.
Copy link
Member

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

Copy link
Member

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

@nicolas-grekas
Copy link
Member

missing entries in CHANGELOG / UPGRADE files

@fabpot
Copy link
Member

fabpot commented Mar 14, 2017

👍

Copy link
Member

@nicolas-grekas nicolas-grekas left a 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.
Copy link
Member

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.
Copy link
Member

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`
Copy link
Member

Choose a reason for hiding this comment

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

Kernel::getEnvParameters()

@@ -19,12 +19,12 @@ class CachePoolsTest extends WebTestCase
{
protected function setUp()
{
$_SERVER['SYMFONY__REDIS_HOST'] = getenv('REDIS_HOST');
$_SERVER['REDIS_HOST'] = getenv('REDIS_HOST');
}
Copy link
Member

Choose a reason for hiding this comment

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

seems unnecessary

Copy link
Member Author

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() ?

Copy link
Member

Choose a reason for hiding this comment

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

I would say yes

@fabpot
Copy link
Member

fabpot commented Mar 20, 2017

Tests are broken.

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

👍

@javiereguiluz
Copy link
Member Author

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.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

@fabpot
Copy link
Member

fabpot commented Mar 21, 2017

Thank you @javiereguiluz.

@fabpot fabpot closed this in a96a997 Mar 21, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
roverwolf added a commit to opensalt/opensalt that referenced this pull request Aug 15, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants