-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Featture: #11746: Allow environment variables to be used in json files #12589
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
base: main
Are you sure you want to change the base?
Conversation
composer.lockPackage changes
Settings · Docs · Powered by Private Packagist |
|
The composer.lock diff comment has been updated to reflect new changes in this PR. |
|
The original ticket asked for environment variables only in auth.json but implementing that would be more work then implementing it for all .json files what do you (moderators) think of this? |
composer.json
Outdated
| "symfony/polyfill-php81": "^1.24", | ||
| "seld/signal-handler": "^2.0" | ||
| "seld/signal-handler": "^2.0", | ||
| "symfony/dotenv": "^5.4" |
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.
| "symfony/dotenv": "^5.4" | |
| "symfony/dotenv": "^5.4 || ^6.4.25 || ^7.1.10 || ^8.0" |
| if (!@mkdir($dir, 0777, true)) { | ||
| throw new \UnexpectedValueException( | ||
| $dir.' does not exist and could not be created.' | ||
| $dir . ' does not exist and could not be created.' |
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.
It'd be great to avoid doing random CS changes together with your PR.. that distracts from the real content.
src/Composer/Json/JsonFile.php
Outdated
|
|
||
| $data = self::$envParser->apply($data, $file); | ||
|
|
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 think this should be optional and not applied to all json files being parsed (including those coming from remote network right now). IMO the best would be that it can be turned on where it makes sense (auth.json, maybe composer.json, I don't think anything else needs this?) by passing a JsonEnvParser into the constructor.. and if none is passed then no env parsing happens. I don't think parseJson needs this ever?
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.
Sorry thinking about this some more.. I think we really should only apply this to the auth.json - which could be done in Factory.php as that's the only place where we really read this.
And it should not use symfony/dotenv actually I think this should be reserved to real env vars.. Because if you're gonna dump stuff on disk then you might as well have it in the auth.json directly, so I'd rather save us some complexity here and not risk loading things we aren't supposed to from .env files.
Use $rootPath rather then __DIR__ Co-authored-by: Jordi Boggiano <[email protected]>
Use references rather then recreating the array structure Co-authored-by: Jordi Boggiano <[email protected]>
|
The composer.lock diff comment has been updated to reflect new changes in this PR. |
|
I’ve updated the code with the functionality you requested. Let me know if this is what you had in mind. |
| $this->io->warning('Dotenv file path is not set.'); | ||
| self::$unreadableEnvWarned = true; |
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 don't see why that should be a warning. And IMO if you want to add .env support it should probably be reading from .env.local => .env as fallback, but then reimplementing all of dotenv libs makes no sense.
Why support dotenv at all? Why not use real env vars?
|
Fixes #11746