Skip to content
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
17 changes: 11 additions & 6 deletions configuration/env_var_processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -745,11 +745,13 @@ Symfony provides the following env var processors:
Tries to convert an environment variable to an actual ``\BackedEnum`` value.
This processor takes the fully qualified name of the ``\BackedEnum`` as an argument::

# App\Enum\Environment
// App\Enum\Suit.php
enum Environment: string
{
case Development = 'dev';
case Production = 'prod';
case Clubs = 'clubs';
case Spades = 'spades';
case Diamonds = 'diamonds';
case Hearts = 'hearts';
}

.. configuration-block::
Expand All @@ -758,7 +760,7 @@ Symfony provides the following env var processors:

# config/services.yaml
parameters:
typed_env: '%env(enum:App\Enum\Environment:APP_ENV)%'
suit: '%env(enum:App\Enum\Suit:CARD_SUIT)%'

.. code-block:: xml

Expand All @@ -773,14 +775,17 @@ Symfony provides the following env var processors:
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<parameters>
<parameter key="typed_env">%env(enum:App\Enum\Environment:APP_ENV)%</parameter>
<parameter key="suit">%env(enum:App\Enum\Suit:CARD_SUIT)%</parameter>
</parameters>
</container>

.. code-block:: php

// config/services.php
$container->setParameter('typed_env', '%env(enum:App\Enum\Environment:APP_ENV)%');
$container->setParameter('suit', '%env(enum:App\Enum\Suit:CARD_SUIT)%');

The value stored in the ``CARD_SUIT`` env var would be a string like `'spades'` but the
application will use the ``Suit::Spdes`` enum value.

.. versionadded:: 6.2

Expand Down