Skip to content

Document how to resolve env var at compile time #21223

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

Merged
merged 1 commit into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions components/dependency_injection/compilation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,21 @@ have the cache will be considered stale.

In the full-stack framework the compilation and caching of the container
is taken care of for you.

.. _resolving-env-vars-at-compile-time:

Resolving Environment Variable At Compile Time
----------------------------------------------

Environment variables value can be resolved at compile time by using the following code::

$parameterValue = $container->resolveEnvPlaceholders(
$container->getParameter('%env(ENV_VAR_NAME)%'),
true // Resolve to actual values
);

.. warning::

Environment variables are usually a runtime concern. One of the major drawbacks of resolving them
at compile time is that you'll need to manually clear the cache when changing their value (which is exactly
what you don't have to do for env vars under normal circumstances).
6 changes: 6 additions & 0 deletions configuration/env_var_processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -912,3 +912,9 @@ To enable the new processor in the app, register it as a service and
tag. If you're using the
:ref:`default services.yaml configuration <service-container-services-load-example>`,
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.

Resolving Environment Variable At Compile Time
----------------------------------------------

Although environment variables are usually a runtime concept, you can also resolve them
:ref:`at compile time <resolving-env-vars-at-compile-time>`.
Comment on lines +916 to +920
Copy link
Contributor Author

@nikophil nikophil Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every search in google about "symfony env var" lead to this page, so it seems useful to have link here to the other page