Skip to content

Commit 9bd0c03

Browse files
committed
Document how to resolve env var at compile time
1 parent 93ccd45 commit 9bd0c03

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

components/dependency_injection/compilation.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,21 @@ 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+
Environment variables value can be resolved at compile time by using the following code::
618+
619+
$parameterValue = $container->resolveEnvPlaceholders(
620+
$container->getParameter('%env(ENV_VAR_NAME)%'),
621+
true // Resolve to actual values
622+
);
623+
624+
.. warning::
625+
626+
Environment variables are usually a runtime concern. One of the major drawbacks of resolving them
627+
at compile time is that you'll need to manually clear the cache when changing their value (which is exactly
628+
what you don't have to do for env vars under normal circumstances).

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+
Although environment variables are usually a runtime concept, you can also resolve them
959+
:ref:`at compile time <resolving-env-vars-at-compile-time>`.

0 commit comments

Comments
 (0)