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
[WIP][DependencyInjection] Issue #7555 - Resolve environment variables at runtime #10138
Conversation
So far, the issues in the build do not seem to be linked to this PR. |
Can I suggest an improvement.. This run-time resolver could also resolve the parameters set via the newly introduced expression engine. |
This could indeed be considered, but this would be a separate PR isn’t it ? |
@@ -25,6 +25,7 @@ | |||
class ParameterBag implements ParameterBagInterface | |||
{ | |||
protected $parameters = array(); | |||
protected $environment_map = array(); |
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.
Property names should use camel case
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.
Thanks
Closing as it does not fix the problem in all cases (see the referenced other PR I created which also failed). |
…env(MY_ENV_VAR)% (nicolas-grekas) This PR was merged into the 3.2-dev branch. Discussion ---------- [DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)% | Q | A | ------------- | --- | Branch? | master | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10138, #7555, #16403, #18155 | License | MIT | Doc PR | symfony/symfony-docs#6918 This is an alternative approach to #18155 for injecting env vars into container configurations. With this PR, anywhere parameters are allowed, one can use `%env(ENV_VAR)%` to inject a dynamic env var. Additionally, if one sets a value to such parameters in e.g. the `parameter.yml` file (`env(ENV_VAR): foo`), this value will be used as a default value when the env var is not defined. If no default value is specified, an `EnvVarNotFoundException` will be thrown at runtime. Unlike previous attempts that also used parameters (#16403), the implementation is compatible with DI extensions: before being dumped, env vars are resolved to uniquely identifiable string placeholders that can get through DI extensions manipulations. When dumped, these unique placeholders are replaced by dynamic calls to a getEnv method.. ping @magnusnordlander @dzuelke @fabpot Commits ------- bac2132 [DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)% syntax
This allows to set a parameter
environment_map
that contains a map[$parameter => $env_var]
. This allows to callParameterBag::resolveEnvironmentMap
even after the bag was initially resolved and frozen. As mentioned by @stof, dependent parameter can not be resolved anymore, so it is forbidden to reference a parameter in the environment map elsewhere. However,resolveEnvironmentMap
will useresolveValue
, so it is possible to reference another parameter in the enviromnent variable.HttpKernel
now callsParameterBag::resolveEnvironmentMap
after theContainer
was fully loaded.I am not entirely sure of the implication of this method with the caching mechanism, the cache warmers, etc. I could use some help from someone with a better understanding of the whole thing.
The only BC break is that
environment_map
is not a valid parameter name anymore, it is reserved.