Skip to content

Commit 0000e79

Browse files
Changing enum: example away from APP_ENV
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 this 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: > 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"), to get rid of the endless indentation, and improve scanability, and get them included in the TOC. Should I create a PR for this?
1 parent f4d4197 commit 0000e79

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
@@ -757,11 +757,13 @@ Symfony provides the following env var processors:
757757

758758
.. code-block:: php
759759
760-
# App\Enum\Environment
760+
// App\Enum\Suit.php
761761
enum Environment: string
762762
{
763-
case Development = 'dev';
764-
case Production = 'prod';
763+
case Clubs = 'clubs';
764+
case Spades = 'spades';
765+
case Diamonds = 'diamonds';
766+
case Hearts = 'hearts';
765767
}
766768
767769
.. configuration-block::
@@ -770,7 +772,7 @@ Symfony provides the following env var processors:
770772
771773
# config/services.yaml
772774
parameters:
773-
typed_env: '%env(enum:App\Enum\Environment:APP_ENV)%'
775+
suit: '%env(enum:App\Enum\Suit:CARD_SUIT)%'
774776
775777
.. code-block:: xml
776778
@@ -785,14 +787,17 @@ Symfony provides the following env var processors:
785787
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
786788
787789
<parameters>
788-
<parameter key="typed_env">%env(enum:App\Enum\Environment:APP_ENV)%</parameter>
790+
<parameter key="suit">%env(enum:App\Enum\Suit:CARD_SUIT)%</parameter>
789791
</parameters>
790792
</container>
791793
792794
.. code-block:: php
793795
794796
// config/services.php
795-
$container->setParameter('typed_env', '%env(enum:App\Enum\Environment:APP_ENV)%');
797+
$container->setParameter('suit', '%env(enum:App\Enum\Suit:CARD_SUIT)%');
798+
799+
The value stored in the ``CARD_SUIT`` env var would be a string like `'spades'` but the
800+
application will use the ``Suit::Spdes`` enum value.
796801

797802
.. versionadded:: 6.2
798803

0 commit comments

Comments
 (0)