Skip to content

Commit a7d5206

Browse files
committed
Add description of the built in envvar processors
1 parent cfed0b8 commit a7d5206

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

configuration/external_parameters.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,86 @@ will be used whenever the corresponding environment variable is *not* found:
9999
// config/services.php
100100
$container->setParameter('env(DATABASE_HOST)', 'localhost');
101101
102+
Environment Variable Processors
103+
-------------------------------
104+
105+
When using environment variables they are always strings by default, but sometimes
106+
you will want to have specific types so that they match the types expected by your code.
107+
108+
.. configuration-block::
109+
110+
.. code-block:: yaml
111+
112+
# config/packages/framework.yaml
113+
framework:
114+
router:
115+
http_port: env(int:HTTP_PORT)
116+
117+
.. code-block:: xml
118+
119+
<!-- config/packages/framework.xml -->
120+
<?xml version="1.0" encoding="UTF-8" ?>
121+
122+
<container xmlns="http://symfony.com/schema/dic/services"
123+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
124+
xmlns:framework="http://symfony.com/schema/dic/symfony"
125+
xsi:schemaLocation="http://symfony.com/schema/dic/services
126+
http://symfony.com/schema/dic/services/services-1.0.xsd
127+
http://symfony.com/schema/dic/symfony
128+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
129+
130+
<framework:config>
131+
<framework:router http_port="%env(int:HTTP_PORT)%" />
132+
</framework:config>
133+
</container>
134+
135+
.. code-block:: php
136+
137+
// config/packages/doctrine.php
138+
$container->loadFromExtension('framework', array(
139+
'router' => array(
140+
'http_port' => '%env(int:HTTP_PORT)%',
141+
)
142+
));
143+
144+
A number of different types are supported:
145+
146+
``env(string):FOO)``
147+
Casts ``FOO`` to a string
148+
149+
``env(bool:FOO)``
150+
Casts ``FOO`` to a bool
151+
152+
``env(int:FOO)``
153+
Casts ``FOO`` to an int
154+
155+
``env(float:FOO)``
156+
Casts ``FOO`` to an float
157+
158+
``env(const:FOO)``
159+
Finds the const value named in ``FOO``
160+
161+
``env(base64:FOO)``
162+
Decodes ``FOO`` that is a base64 encoded string
163+
164+
``env(json:FOO)``
165+
Decodes ``FOO`` that is a json encoded string into either an array or ``null``
166+
167+
``env(resolve:FOO)``
168+
Resolves references in the string ``FOO`` to other parameters
169+
170+
``env(csv:FOO)``
171+
Decodes ``FOO`` that is a single row of comma seperated values
172+
173+
``env(file:FOO)``
174+
Reads the contents of a file named in ``FOO``
175+
176+
It is also possible to combine the processors:
177+
178+
``env(json:file:FOO)``
179+
Reads the contents of a file named in ``FOO``, and then decode it from json, resulting in an array or ``null``
180+
181+
102182
.. _configuration-env-var-in-prod:
103183

104184
Configuring Environment Variables in Production

0 commit comments

Comments
 (0)