Skip to content

[DependencyInjection] Add defined prefix for env var processor #18464

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
Jun 29, 2023
Merged
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
37 changes: 37 additions & 0 deletions configuration/env_var_processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,43 @@ Symfony provides the following env var processors:

The ``env(enum:...)`` env var processor was introduced in Symfony 6.2.

``env(defined:NO_FOO)``
Evaluates to ``true`` if the env var is defined (ie: different from ``''`` or ``null``), ``false`` otherwise.

.. configuration-block::

.. code-block:: yaml

# config/services.yaml
parameters:
typed_env: '%env(defined:NO_FOO)%'

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<parameters>
<parameter key="typed_env"'%env(defined:NO_FOO)%</parameter>
</parameters>
</container>

.. code-block:: php

// config/services.php
$container->setParameter('typed_env', '%env(defined:NO_FOO)%');

.. versionadded:: 6.4

The ``env(defined:...)`` env var processor was introduced in Symfony 6.4.

It is also possible to combine any number of processors:

.. configuration-block::
Expand Down