Skip to content

Commit 49cc99a

Browse files
committed
minor #17507 Changing enum: example away from APP_ENV (ThomasLandauer)
This PR was submitted for the 6.2 branch but it was merged into the 6.3 branch instead. Discussion ---------- Changing `enum:` example away from APP_ENV https://symfony.com/doc/current/configuration/env_var_processors.html#built-in-environment-variable-processors Reason: When I first read this, I was expecting that the Symfony-internal ways to get the environment (`{{ app.environment }}`, `$routingConfigurator->env()` ,etc.) would now return the enum. But this is not the case. So if you explain the new processor with exactly this example, there needs to be a caution box, explaining that Symfony's methods still return the string. * If you don't agree with this change, I'd still open a separate PR to add the following info (taken from https://symfony.com/blog/new-in-symfony-6-2-improved-enum-support#enums-in-environment-variables), cause that's a missing piece of information here: > 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. * Besides, as the list of processors is getting longer and longer, I'd suggest to create a sub-heading for each (under "Built-In Environment Variable Processors") and sort them alphabetically, to get rid of the endless indentation, and improve scanability, and get them included in the TOC. Should I create a PR for this? If yes, for which version? Commits ------- c099758 Changing `enum:` example away from APP_ENV
2 parents d5d5898 + c099758 commit 49cc99a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

configuration/env_var_processors.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,13 @@ Symfony provides the following env var processors:
745745
Tries to convert an environment variable to an actual ``\BackedEnum`` value.
746746
This processor takes the fully qualified name of the ``\BackedEnum`` as an argument::
747747

748-
# App\Enum\Environment
748+
// App\Enum\Suit.php
749749
enum Environment: string
750750
{
751-
case Development = 'dev';
752-
case Production = 'prod';
751+
case Clubs = 'clubs';
752+
case Spades = 'spades';
753+
case Diamonds = 'diamonds';
754+
case Hearts = 'hearts';
753755
}
754756

755757
.. configuration-block::
@@ -758,7 +760,7 @@ Symfony provides the following env var processors:
758760
759761
# config/services.yaml
760762
parameters:
761-
typed_env: '%env(enum:App\Enum\Environment:APP_ENV)%'
763+
suit: '%env(enum:App\Enum\Suit:CARD_SUIT)%'
762764
763765
.. code-block:: xml
764766
@@ -773,14 +775,17 @@ Symfony provides the following env var processors:
773775
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
774776
775777
<parameters>
776-
<parameter key="typed_env">%env(enum:App\Enum\Environment:APP_ENV)%</parameter>
778+
<parameter key="suit">%env(enum:App\Enum\Suit:CARD_SUIT)%</parameter>
777779
</parameters>
778780
</container>
779781
780782
.. code-block:: php
781783
782784
// config/services.php
783-
$container->setParameter('typed_env', '%env(enum:App\Enum\Environment:APP_ENV)%');
785+
$container->setParameter('suit', '%env(enum:App\Enum\Suit:CARD_SUIT)%');
786+
787+
The value stored in the ``CARD_SUIT`` env var would be a string like `'spades'` but the
788+
application will use the ``Suit::Spdes`` enum value.
784789

785790
.. versionadded:: 6.2
786791

0 commit comments

Comments
 (0)