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

Skip to content

[Dotenv] Add support for overriding existing envs #23720

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 2 commits into from
Closed

[Dotenv] Add support for overriding existing envs #23720

wants to merge 2 commits into from

Conversation

voronkovich
Copy link
Contributor

@voronkovich voronkovich commented Jul 30, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #23723
License MIT

Every time I changed my .env file I need to restart the WebServerBundle's server, because the Dotenv component doesn't override the existing environment variables. This PR adds a dedicated method to overload the environment variables.
Having an ability to overload the.env file, we could solve the issue like this:

// public/index.php
if (getenv('APP_DEBUG') && file_exists(__DIR__.'/../.env')) {
    (new Dotenv())->overload(__DIR__.'/../.env');
} elseif (!getenv('APP_ENV')) {
    (new Dotenv())->load(__DIR__.'/../.env');
}

@Taluu
Copy link
Contributor

Taluu commented Jul 31, 2017

It if it is in a .env, the DotEnv overwrites only if the var doesn't exist. When you do a putenv (and manipulate $_ENV, $_SERVER variables), it affects only the running process, and does not modify it on the global for all the runs.

So basically, this means that the problem is elsewhere. I'm 👎 for this patch in particular.

@chalasr
Copy link
Member

chalasr commented Jul 31, 2017

Other libraries address this with a dedicated method, that is better IMHO. See
https://github.com/vlucas/phpdotenv/blob/master/src/Dotenv.php
https://github.com/bkeepers/dotenv/blob/master/lib/dotenv.rb#L30

@voronkovich voronkovich changed the base branch from master to 3.4 July 31, 2017 12:17
@voronkovich
Copy link
Contributor Author

@chalasr, thanks for the links! I've added the dedicated method as you suggested!

@voronkovich voronkovich reopened this Jul 31, 2017
@chalasr chalasr added this to the 3.4 milestone Jul 31, 2017
@chalasr chalasr added the Dotenv label Jul 31, 2017
@fabpot
Copy link
Member

fabpot commented Aug 1, 2017

While I agree that the references bug should be fixed, I'm 👎 for adding such a method which I consciously decided to not add when I design the library.

@chalasr
Copy link
Member

chalasr commented Aug 2, 2017

@fabpot The first approach was a flag set through the constructor. Personally I think we don't need such state hence suggesting a new method (a new arg for the load() method would do the job as well).
Refreshing env vars for each request cannot be done using DotEnv if we don't want it to be able to overload (or clean up) already defined env vars.

@chalasr
Copy link
Member

chalasr commented Aug 6, 2017

Can't we close this one in favor of #23799?

@nicolas-grekas
Copy link
Member

yes, same purpose

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