Skip to content

Commit 4f8ddfe

Browse files
committed
minor #21223 Document how to resolve env var at compile time (nikophil)
This PR was submitted for the 7.3 branch but it was merged into the 6.4 branch instead. Discussion ---------- Document how to resolve env var at compile time see https://symfony-devs.slack.com/archives/C3EQ7S3MJ/p1752843597330219 Resolving env var at compile is a unusual case, but this could be helpful from time to time. This piece of information is hard to find (I've found it [here](symfony/symfony#22456 (comment))), and it could be interesting to have it documented, with a meaningful warning. Commits ------- 4aaca90 Document how to resolve env var at compile time
2 parents b146483 + 4aaca90 commit 4f8ddfe

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
@@ -612,3 +612,21 @@ have the cache will be considered stale.
612612

613613
In the full-stack framework the compilation and caching of the container
614614
is taken care of for you.
615+
616+
.. _resolving-env-vars-at-compile-time:
617+
618+
Resolving Environment Variable At Compile Time
619+
----------------------------------------------
620+
621+
Environment variables value can be resolved at compile time by using the following code::
622+
623+
$parameterValue = $container->resolveEnvPlaceholders(
624+
$container->getParameter('%env(ENV_VAR_NAME)%'),
625+
true // Resolve to actual values
626+
);
627+
628+
.. warning::
629+
630+
Environment variables are usually a runtime concern. One of the major drawbacks of resolving them
631+
at compile time is that you'll need to manually clear the cache when changing their value (which is exactly
632+
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
@@ -912,3 +912,9 @@ To enable the new processor in the app, register it as a service and
912912
tag. If you're using the
913913
:ref:`default services.yaml configuration <service-container-services-load-example>`,
914914
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.
915+
916+
Resolving Environment Variable At Compile Time
917+
----------------------------------------------
918+
919+
Although environment variables are usually a runtime concept, you can also resolve them
920+
:ref:`at compile time <resolving-env-vars-at-compile-time>`.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy