-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] ContainerBuilder::compile() can optionally resolve env vars in parameter bag #21460
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
👍 |
@@ -555,15 +556,27 @@ public function prependExtensionConfig($name, array $config) | |||
* * The parameter bag is frozen; | |||
* * Extension loading is disabled. | |||
*/ | |||
public function compile() | |||
public function compile(/* $resolveEnvPlaceholders = false */) |
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.
How about using a flag (e.g. self::RESOLVE_ENV_PLACEHOLDERS
) instead of a boolean, so that additional features may be introduced without requiring additional parameters?
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.
IMHO, we shouldn't plan for additional unplanned features :) This can be changed easily in the future if needed.
$_ENV['DUMMY_ENV_VAR'] = 'du%%y'; | ||
|
||
$container = new ContainerBuilder(); | ||
$container->setParameter('bar', '%% %env(DUMMY_ENV_VAR)%'); |
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 will happen in the other two cases: 1) undefined env var; 2) undefined env var, but default value defined for it. Should we add those cases to this test too?
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.
same as usual, this is exactly the same code/logic
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.
tests added
8b278b2
to
13ea687
Compare
Can you add some docs in the phpdocs? |
13ea687
to
ff4c1f0
Compare
phpdoc added |
ff4c1f0
to
1a2b1cb
Compare
@@ -555,16 +556,37 @@ public function prependExtensionConfig($name, array $config) | |||
* * Parameter values are resolved; | |||
* * The parameter bag is frozen; | |||
* * Extension loading is disabled. | |||
* | |||
* @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved using the current | |||
* env vars or be replaced by uniquely identifiable placeholders |
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.
That describes what it does, but I'd like to understand also when I should pass true
here.
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.
comment updated
a735b0e
to
6ea3a24
Compare
6ea3a24
to
a3fd512
Compare
Thank you @nicolas-grekas. |
…e env vars in parameter bag (nicolas-grekas) This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] ContainerBuilder::compile() can optionally resolve env vars in parameter bag | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #21420 | License | MIT | Doc PR | - Here is a new feature allowing one to do `$container->compile(true)` and get the env vars resolved using the current env. Commits ------- a3fd512 [DI] ContainerBuilder::compile() can optionally resolve env vars in parameter bag
I tried to capture how to do this in a stackoverflow answer. |
@zippy1981 Thanks for that SO answer, however I can't seem to get it working. If I replace |
@pwm why would you want to use this argument in your bundle ? |
@stof I'm trying to get env vars work as monolog config values, pretty much exactly like the SO entry above, but I get an |
Here is a new feature allowing one to do
$container->compile(true)
and get the env vars resolved using the current env.