Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Dotenv] add loadEnv(), a smoother alternative to loadForEnv()#29129
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ogizanagi commentedNov 7, 2018
But not aligned with
I'm used to occasionally start phpunit with |
nicolas-grekas commentedNov 7, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sure. create-react-app has the behavior that best matches Symfony, so why should we care more about bkeepers?
Nope it won't, useless you defined |
521236f to0622753Compareogizanagi commentedNov 7, 2018
Based on which facts? 🤔
Indeed. We provided the value inhttps://github.com/symfony/recipes/blob/5b3ce909504b9366405820c49bc9f0e13ac4be54/symfony/phpunit-bridge/4.1/phpunit.xml.dist#L14, but that's not relevant with planned changes.
So, what do you preconize for CI appart from either removing |
nicolas-grekas commentedNov 7, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
You're asking because you think we should keep the current behavior? My arguments for the new one are:
yes, this is described inhttps://metaskills.net/2013/10/03/using-dotenv-in-rails/
the reason is that tests run in a special set of configuration and the very purpose of .env.test is to commit that configuration. If you don't want to follow what the devs set there, you have to do extra work. OR if your test setup needs to be flexible, you can omit defining those vars in .env files. |
nicolas-grekas commentedNov 7, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
BTW, about the test env: if, for some FOO env var, one would like to give control to the real env while that var is defined in |
dunglas commentedNov 7, 2018
👍 on my side. Many people will use Create React App and Symfony together in the same project, Rails + Symfony will definitely be less popular.
Are you sure about that? According to their docs, it's not the case by default, but you can use |
0622753 toe2af3b9Comparenicolas-grekas commentedNov 7, 2018
OK, overloading for test removed. Ready. |
ogizanagi left a comment
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.
What would it be like in the recipe with the--env re-introduction, though?
Dotenv::loadEnv('.env','APP_ENV',$input->getParameterOption(['--env','-e'],'dev',true));
?--env would be ignored ifAPP_ENV env var is set...which is fine to me. Just sayin' :)
e2af3b9 tod7d786bComparenicolas-grekas commentedNov 8, 2018
Right now, |
d7d786b to0cf9acbCompare…nv() (nicolas-grekas)This PR was merged into the 4.2-dev branch.Discussion----------[Dotenv] add loadEnv(), a smoother alternative to loadForEnv()| Q | A| ------------- | ---| Branch? | 4.2| Bug fix? | yes| New feature? | no| BC breaks? | yes (4.2-only)| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -This PR replaces the `loadForEnv()` method introduced in#28533 by a new `loadEnv()` method.- It accepts only one mandatory argument: `$path`, which is the path to the `.env` file.- The 2nd argument is optional and defines the name of the environment variable that defines the Symfony env. This plays better with the current practice of defining the env in `.env` (`loadForEnv()` requires knowing the env before being called, leading to a chicken-n-egg situation that `loadEnv()` avoids.)- the possibility to load several files at once is removed. We don't have a use case for it and those who do can call `loadEnv()` in a loop anyway.In addition to $path (.env), the following files are loaded, the latter taking precedence in this order:.env < env.local < .env.$env < .env.$env.localNote that `loadForEnv()` used to give higher precedence to .env.local vs .env.$env.The new behavior is aligned with [the order used by create-react-app](https://github.com/facebook/create-react-app/blob/master/docusaurus/docs/adding-custom-environment-variables.md#what-other-env-files-can-be-used). It also allows overriding the env in .env.local, which should be convenient for DX.Last but not least, the "test" env has this special behaviors:- `.env.local` file is skipped for the "test" env (same as before and as in create-react-app)- ~vars defined in .env files **override** real env vars (similar to what Rails' dotenv does: you don't want your tests to randomly fail because of some real env vars)~.Commits-------0cf9acb [Dotenv] add loadEnv(), a smoother alternative to loadForEnv()
Uh oh!
There was an error while loading.Please reload this page.
This PR replaces the
loadForEnv()method introduced in#28533 by a newloadEnv()method.$path, which is the path to the.envfile..env(loadForEnv()requires knowing the env before being called, leading to a chicken-n-egg situation thatloadEnv()avoids.)loadEnv()in a loop anyway.In addition to $path (.env), the following files are loaded, the latter taking precedence in this order:
.env < env.local < .env.$env < .env.$env.local
Note that
loadForEnv()used to give higher precedence to .env.local vs .env.$env.The new behavior is aligned withthe order used by create-react-app. It also allows overriding the env in .env.local, which should be convenient for DX.
Last but not least, the "test" env has this special behaviors:
.env.localfile is skipped for the "test" env (same as before and as in create-react-app)vars defined in .env filesoverride real env vars (similar to what Rails' dotenv does: you don't want your tests to randomly fail because of some real env vars).