This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Exception
Fabien Potencier 1bcade56e6 feature #19681 [DI] Allow injecting ENV parameters at runtime using %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        | https://github.com/symfony/symfony-docs/pull/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
2016-09-15 10:44:52 -07:00
..
BadMethodCallException.php updated license blocks 2012-03-31 18:00:32 -03:00
EnvNotFoundException.php [DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)% syntax 2016-09-10 12:12:34 +02:00
EnvParameterException.php [DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)% syntax 2016-09-10 12:12:34 +02:00
ExceptionInterface.php [DependencyInjection] Format base exception classes consistently 2011-12-04 22:17:41 -08:00
InvalidArgumentException.php [DependencyInjection] Format base exception classes consistently 2011-12-04 22:17:41 -08:00
LogicException.php updated license blocks 2012-03-31 18:00:32 -03:00
OutOfBoundsException.php updated license blocks 2012-03-31 18:00:32 -03:00
ParameterCircularReferenceException.php [DependencyInjection] Added missing support for setting previous exception 2013-03-09 06:37:35 +01:00
ParameterNotFoundException.php [DependencyInjection] Improve ParameterNotFoundException when accessing a nested parameter 2016-09-14 14:25:50 -07:00
RuntimeException.php updated license blocks 2012-03-31 18:00:32 -03:00
ServiceCircularReferenceException.php [DependencyInjection] Added missing support for setting previous exception 2013-03-09 06:37:35 +01:00
ServiceNotFoundException.php [DependencyInjection] fixed ? position in some exception messages (refs #7861) 2013-05-01 06:24:56 +02:00