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

Skip to content

Conversation

@Matthiasklaasse
Copy link

@Matthiasklaasse Matthiasklaasse commented Nov 2, 2025

  • ✨ Added JsonEnvParser so JsonFile can resolve ${VAR} placeholders from the project .env.
  • 🔄 Preserved backward compatibility: missing env values trigger a warning but return the literal placeholder.
  • 🌍 Every .json file (processed by the JsonFile class) is affected and can now take enviroment variables (even 3th party composer.json's).

Fixes #11746

@private-packagist
Copy link
Contributor

private-packagist bot commented Nov 2, 2025

composer.lock

Package changes

Package Operation From To About
composer/ca-bundle upgrade 1.5.8 1.5.9 diff
justinrainbow/json-schema upgrade 6.6.0 6.6.1 diff

Settings · Docs · Powered by Private Packagist

@private-packagist
Copy link
Contributor

The composer.lock diff comment has been updated to reflect new changes in this PR.

@Matthiasklaasse
Copy link
Author

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?

@Matthiasklaasse Matthiasklaasse changed the title Added request from #11746: Allow environment variables to be used in auth.json Featture/#11746: Allow environment variables to be used in json files Nov 3, 2025
@Matthiasklaasse Matthiasklaasse changed the title Featture/#11746: Allow environment variables to be used in json files Featture: #11746: Allow environment variables to be used in json files Nov 3, 2025
composer.json Outdated
"symfony/polyfill-php81": "^1.24",
"seld/signal-handler": "^2.0"
"seld/signal-handler": "^2.0",
"symfony/dotenv": "^5.4"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"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.'
Copy link
Member

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.

Comment on lines 369 to 371

$data = self::$envParser->apply($data, $file);

Copy link
Member

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?

Copy link
Member

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.

@Seldaek Seldaek added this to the 2.10 milestone Nov 6, 2025
Matthiasklaasse and others added 2 commits November 6, 2025 13:22
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]>
@Seldaek Seldaek modified the milestones: 2.10, 2.9 Nov 6, 2025
@private-packagist
Copy link
Contributor

The composer.lock diff comment has been updated to reflect new changes in this PR.

@Matthiasklaasse
Copy link
Author

I’ve updated the code with the functionality you requested. Let me know if this is what you had in mind.

Comment on lines +71 to +72
$this->io->warning('Dotenv file path is not set.');
self::$unreadableEnvWarned = true;
Copy link
Member

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?

@naderman
Copy link
Member

naderman commented Nov 10, 2025

  • Agree that only auth.json replacements should happen. Especially not composer.json, which could lead people to do things like requiring an environment defined package name or version, which would make composer.json way too dynamic and ambiguous especially for any kind of tooling operating on it.

  • Like Jordi I'm not sure I see the value in supporting .env files here, then you may as well just write an auth.json file to disk? To agree to adding that, I would need to see an actually clear use-case that seems relevant enough to affect a lot of users positively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow environment variables to be used in auth.json

3 participants