Skip to content

Commit 86a577a

Browse files
committed
feature #14976 [DependencyInjection] Negated (not:) env var processor (bpolaszek)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [DependencyInjection] Negated (not:) env var processor This PR adds documentation for symfony/symfony#40169: negated env var processor: ------ Casts to a bool (just as `env(bool:...)` does) except it returns the inverted value(falsy values are returned as `true`, truthy values are returned as `false`): ```yaml # config/services.yaml parameters: safe_for_production: '%env(not:APP_DEBUG)%' ``` Commits ------- 3ff812d [DependencyInjection] Negated (not:) env var processor
2 parents 1839389 + 3ff812d commit 86a577a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

configuration/env_var_processors.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,46 @@ Symfony provides the following env var processors:
136136
'http_method_override' => '%env(bool:HTTP_METHOD_OVERRIDE)%',
137137
]);
138138
139+
``env(not:FOO)``
140+
141+
.. versionadded:: 5.3
142+
143+
The ``not:`` env var processor was introduced in Symfony 5.3.
144+
145+
Casts ``FOO`` to a bool (just as ``env(bool:...)`` does) except it returns the inverted value
146+
(falsy values are returned as ``true``, truthy values are returned as ``false``):
147+
148+
.. configuration-block::
149+
150+
.. code-block:: yaml
151+
152+
# config/services.yaml
153+
parameters:
154+
safe_for_production: '%env(not:APP_DEBUG)%'
155+
156+
.. code-block:: xml
157+
158+
<!-- config/services.xml -->
159+
<?xml version="1.0" encoding="UTF-8" ?>
160+
<container xmlns="http://symfony.com/schema/dic/services"
161+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
162+
xmlns:framework="http://symfony.com/schema/dic/symfony"
163+
xsi:schemaLocation="http://symfony.com/schema/dic/services
164+
https://symfony.com/schema/dic/services/services-1.0.xsd
165+
http://symfony.com/schema/dic/symfony
166+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
167+
168+
<parameters>
169+
<parameter key="safe_for_production">%env(not:APP_DEBUG)%</parameter>
170+
</parameters>
171+
172+
</container>
173+
174+
.. code-block:: php
175+
176+
// config/services.php
177+
$container->setParameter('safe_for_production', '%env(not:APP_DEBUG)%');
178+
139179
``env(int:FOO)``
140180
Casts ``FOO`` to an int.
141181

0 commit comments

Comments
 (0)