Skip to content

Commit 6a164b6

Browse files
committed
Merge branch '6.4' into 7.2
* 6.4: Minor reword Document how to resolve env var at compile time
2 parents 46a58cd + 696827c commit 6a164b6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

components/dependency_injection/compilation.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,25 @@ have the cache will be considered stale.
608608

609609
In the full-stack framework the compilation and caching of the container
610610
is taken care of for you.
611+
612+
.. _resolving-env-vars-at-compile-time:
613+
614+
Resolving Environment Variable At Compile Time
615+
----------------------------------------------
616+
617+
.. caution::
618+
619+
**This practice is discouraged**. Use it only if you fully understand the implications.
620+
621+
By default, environment variables are resolved at runtime. However, you can
622+
force their resolution at compile time using the following code::
623+
624+
$parameterValue = $container->resolveEnvPlaceholders(
625+
$container->getParameter('%env(ENV_VAR_NAME)%'),
626+
true // resolve to actual values
627+
);
628+
629+
However, a **major drawback** of this approach is that you must manually clear
630+
the cache when changing the value of an environment variable. This goes
631+
against the typical behavior of environment variables, which are designed
632+
to be dynamic and not require cache invalidation.

configuration/env_var_processors.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,9 @@ To enable the new processor in the app, register it as a service and
951951
tag. If you're using the
952952
:ref:`default services.yaml configuration <service-container-services-load-example>`,
953953
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.
954+
955+
Resolving Environment Variable At Compile Time
956+
----------------------------------------------
957+
958+
Environment variables are resolved at runtime, but you can also resolve them
959+
:ref:`at compile time <resolving-env-vars-at-compile-time>`.

0 commit comments

Comments
 (0)