-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Runtime] Add dotenv_overload option to SymfonyRuntime to tell Dotenv to override existing vars #41681
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
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.
Can you tell us a bit more about the use case? because real env vars should always win. Don't you have control over them at all? This also means that parsing happens 100% of the time, contrary to what .env.local.php allows. Not sure we want to make this a mainstream option.
I have to deploy some projects on a "staging" server that contains dozens of projects. Some env vars already exist at the system level (for example: APP_ENV=dev). It's a mistake from the past but I guess some projects out of my perimeter might rely on it. I don't want to break everything and I don't have the time to check/fix every projects. So it's faster and safer to use the "overload" feature for the projects I care about 😄 The performance overhead doesn't matter in my case. |
… to override existing vars
08319b2
to
035ac95
Compare
How about this would be integrated into composer dump-env instead? Having something like |
->bootEnv($options['project_dir'].'/'.($options['dotenv_path'] ?? '.env'), 'dev', (array) ($options['test_envs'] ?? ['test'])); | ||
->bootEnv($fullDotenvPath, 'dev', (array) ($options['test_envs'] ?? ['test'])); | ||
if ($options['dotenv_overload'] ?? false) { | ||
$dotenv->overload($fullDotenvPath); |
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.
Instead of this, I would welcome a new argument $overload
argument on bootEnv()
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.
Do you mean calling $this->overload()
at the end of bootEnv()
?
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 mean calling populate()
with $overrideExistingVars
and doLoad()
with the same arg instead of load()
…adEnv() and dotenv_overload to SymfonyRuntime (fancyweb) This PR was merged into the 5.4 branch. Discussion ---------- [Dotenv] Add $overrideExistingVars to bootEnv() and loadEnv() and dotenv_overload to SymfonyRuntime | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #41681 (comment) | License | MIT | Doc PR | - The goal is to be able to use `bootEnv()` and `loadEnv()` and override existing vars directly instead of having to call `overload()` in a second time. Commits ------- bcb0592 [Dotenv][Runtime] Add $overrideExistingVars to bootEnv() and loadEnv() and dotenv_overload to SymfonyRuntime
Proposing this as bug fix because it's retro compatible and it looks like it was "forgotten".
My use case is that I have projects with:
I think it's not currently possible to migrate this behavior to the new Runtime component.
After: