Skip to content

Commit 971073b

Browse files
committed
minor #16945 [DependencyInjection] Add enum env var processor documentation (alexandre-daubois)
This PR was merged into the 6.2 branch. Discussion ---------- [DependencyInjection] Add `enum` env var processor documentation Closes #16922 Commits ------- 05a80d2 Add `enum` env var processor documentation
2 parents 7991e5a + 05a80d2 commit 971073b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

configuration/env_var_processors.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,49 @@ Symfony provides the following env var processors:
698698
],
699699
]);
700700
701+
``env(enum:FooEnum:BAR)``
702+
Tries to convert an environment variable to an actual ``\BackedEnum`` value. This processor takes the fully qualified
703+
name of the ``\BackedEnum`` as an argument.
704+
705+
.. code-block:: php
706+
707+
# App\Enum\Environment
708+
enum Environment: string
709+
{
710+
case Development = 'dev';
711+
case Production = 'prod';
712+
}
713+
714+
.. configuration-block::
715+
716+
.. code-block:: yaml
717+
718+
# config/services.yaml
719+
parameters:
720+
typed_env: '%env(enum:App\Enum\Environment:APP_ENV)%'
721+
722+
.. code-block:: xml
723+
724+
<!-- config/services.xml -->
725+
<?xml version="1.0" encoding="UTF-8" ?>
726+
<container xmlns="http://symfony.com/schema/dic/services"
727+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
728+
xmlns:framework="http://symfony.com/schema/dic/symfony"
729+
xsi:schemaLocation="http://symfony.com/schema/dic/services
730+
https://symfony.com/schema/dic/services/services-1.0.xsd
731+
http://symfony.com/schema/dic/symfony
732+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
733+
734+
<parameters>
735+
<parameter key="typed_env">%env(enum:App\Enum\Environment:APP_ENV)%</parameter>
736+
</parameters>
737+
</container>
738+
739+
.. code-block:: php
740+
741+
// config/services.php
742+
$container->setParameter('typed_env', '%env(enum:App\Enum\Environment:APP_ENV)%');
743+
701744
It is also possible to combine any number of processors:
702745

703746
.. configuration-block::

0 commit comments

Comments
 (0)