Skip to content

[DependencyInjection] Changing enum: example away from APP_ENV #17507

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
Jan 23, 2024
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