@@ -60,7 +60,7 @@ variable in your service container configuration, you can reference it using
6060 $container->loadFromExtension('doctrine', array(
6161 'dbal' => array(
6262 'host' => '%env(DATABASE_HOST)%',
63- )
63+ ),
6464 ));
6565
6666 You can also give the ``env() `` parameters a default value: the default value
@@ -145,7 +145,7 @@ Environment Variable Processors
145145.. versionadded :: 3.4
146146 Environment variable processors were introduced in Symfony 3.4.
147147
148- The values of the environment variables are considered strings by default.
148+ The values of environment variables are considered strings by default.
149149However, your code may expect other data types, like integers or booleans.
150150Symfony solves this problem with *processors *, which modify the contents of the
151151given environment variables. The following example uses the integer processor to
@@ -164,7 +164,6 @@ turn the value of the ``HTTP_PORT`` env var into an integer:
164164
165165 <!-- config/packages/framework.xml -->
166166 <?xml version =" 1.0" encoding =" UTF-8" ?>
167-
168167 <container xmlns =" http://symfony.com/schema/dic/services"
169168 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
170169 xmlns : framework =" http://symfony.com/schema/dic/symfony"
@@ -174,57 +173,152 @@ turn the value of the ``HTTP_PORT`` env var into an integer:
174173 http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
175174
176175 <framework : config >
177- <framework : router http_port =" %env(int:HTTP_PORT)%" />
176+ <framework : router http-port =" %env(int:HTTP_PORT)%" />
178177 </framework : config >
179178 </container >
180179
181180 .. code-block :: php
182181
183- // config/packages/doctrine .php
182+ // config/packages/framework .php
184183 $container->loadFromExtension('framework', array(
185184 'router' => array(
186185 'http_port' => '%env(int:HTTP_PORT)%',
187- )
186+ ),
188187 ));
189188
190189 Symfony provides the following env var processors:
191190
192191``env(string:FOO) ``
193192 Casts ``FOO `` to a string:
194193
195- .. code -block :: yaml
194+ .. configuration -block ::
196195
197- parameters :
198- env(SECRET) : " some_secret"
199- framework :
200- secret : ' %env(string:SECRET)%'
196+ .. code-block :: yaml
197+
198+ # config/packages/framework.yaml
199+ parameters :
200+ env(SECRET) : ' some_secret'
201+ framework :
202+ secret : ' %env(string:SECRET)%'
203+
204+ .. code-block :: xml
205+
206+ <!-- config/packages/framework.xml -->
207+ <?xml version =" 1.0" encoding =" UTF-8" ?>
208+ <container xmlns =" http://symfony.com/schema/dic/services"
209+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
210+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
211+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
212+ http://symfony.com/schema/dic/services/services-1.0.xsd
213+ http://symfony.com/schema/dic/symfony
214+ http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
215+
216+ <parameters >
217+ <parameter key =" env(SECRET)" >some_secret</parameter >
218+ </parameters >
219+
220+ <framework : config secret =" %env(string:SECRET)%" />
221+ </container >
222+
223+ .. code-block :: php
224+
225+ // config/packages/framework.php
226+ $container->setParameter('env(SECRET)', 'some_secret');
227+ $container->loadFromExtension('framework', array(
228+ 'secret' => '%env(string:SECRET)%',
229+ ));
201230
202231 ``env(bool:FOO) ``
203232 Casts ``FOO `` to a bool:
204233
205- .. code -block :: yaml
234+ .. configuration -block ::
206235
207- parameters :
208- env(HTTP_METHOD_OVERRIDE) : " true"
209- framework :
210- http_method_override : ' %env(bool:HTTP_METHOD_OVERRIDE)%'
236+ .. code-block :: yaml
237+
238+ # config/packages/framework.yaml
239+ parameters :
240+ env(HTTP_METHOD_OVERRIDE) : ' true'
241+ framework :
242+ http_method_override : ' %env(bool:HTTP_METHOD_OVERRIDE)%'
243+
244+ .. code-block :: xml
245+
246+ <!-- config/packages/framework.xml -->
247+ <?xml version =" 1.0" encoding =" UTF-8" ?>
248+ <container xmlns =" http://symfony.com/schema/dic/services"
249+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
250+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
251+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
252+ http://symfony.com/schema/dic/services/services-1.0.xsd
253+ http://symfony.com/schema/dic/symfony
254+ http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
255+
256+ <parameters >
257+ <parameter key =" env(HTTP_METHOD_OVERRIDE)" >true</parameter >
258+ </parameters >
259+
260+ <framework : config http-methode-override =" %env(bool:HTTP_METHOD_OVERRIDE)%" />
261+ </container >
262+
263+ .. code-block :: php
264+
265+ // config/packages/framework.php
266+ $container->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true');
267+ $container->loadFromExtension('framework', array(
268+ 'http_method_override' => '%env(bool:HTTP_METHOD_OVERRIDE)%',
269+ ));
211270
212271 ``env(int:FOO) ``
213272 Casts ``FOO `` to an int.
214273
215274``env(float:FOO) ``
216- Casts ``FOO `` to an float.
275+ Casts ``FOO `` to a float.
217276
218277``env(const:FOO) ``
219278 Finds the const value named in ``FOO ``:
220279
221- .. code-block :: yaml
222-
223- parameters :
224- env(HEALTH_CHECK_METHOD) : " Symfony\C omponent\H ttpFoundation\R equest:METHOD_HEAD"
225- security :
226- access_control :
227- - { path: '^/health-check$', methods: '%env(const:HEALTH_CHECK_METHOD)%' }
280+ .. configuration-block ::
281+
282+ .. code-block :: yaml
283+
284+ # config/packages/security.yaml
285+ parameters :
286+ env(HEALTH_CHECK_METHOD) : ' Symfony\Component\HttpFoundation\Request::METHOD_HEAD'
287+ security :
288+ access_control :
289+ - { path: '^/health-check$', methods: '%env(const:HEALTH_CHECK_METHOD)%' }
290+
291+ .. code-block :: xml
292+
293+ <!-- config/packages/security.xml -->
294+ <?xml version =" 1.0" encoding =" UTF-8" ?>
295+ <container xmlns =" http://symfony.com/schema/dic/services"
296+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
297+ xmlns : security =" http://symfony.com/schema/dic/security"
298+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
299+ http://symfony.com/schema/dic/services/services-1.0.xsd" >
300+
301+ <parameters >
302+ <parameter key =" env(HEALTH_CHECK_METHOD)" >Symfony\Component\HttpFoundation\Request::METHOD_HEAD</parameter >
303+ </parameters >
304+
305+ <security : config >
306+ <rule path =" ^/health-check$" methods =" %env(const:HEALTH_CHECK_METHOD)%" />
307+ </security : config >
308+ </container >
309+
310+ .. code-block :: php
311+
312+ // config/packages/security.php
313+ $container->setParameter('env(HEALTH_CHECK_METHOD)', 'Symfony\Component\HttpFoundation\Request::METHOD_HEAD');
314+ $container->loadFromExtension('security', array(
315+ 'access_control' => array(
316+ array(
317+ 'path' => '^/health-check$',
318+ 'methods' => '%env(const:HEALTH_CHECK_METHOD)%',
319+ ),
320+ ),
321+ ));
228322
229323 ``env(base64:FOO) ``
230324 Decodes the content of ``FOO ``, which is a base64 encoded string.
@@ -233,34 +327,123 @@ Symfony provides the following env var processors:
233327 Decodes the content of ``FOO ``, which is a JSON encoded string. It returns
234328 either an array or ``null ``:
235329
236- .. code -block :: yaml
330+ .. configuration -block ::
237331
238- parameters :
239- env(TRUSTED_HOSTS) : " ['10.0.0.1', '10.0.0.2']"
240- framework :
241- trusted_hosts : ' %env(json:TRUSTED_HOSTS)%'
332+ .. code-block :: yaml
333+
334+ # config/packages/framework.yaml
335+ parameters :
336+ env(TRUSTED_HOSTS) : ' ["10.0.0.1", "10.0.0.2"]'
337+ framework :
338+ trusted_hosts : ' %env(json:TRUSTED_HOSTS)%'
339+
340+ .. code-block :: xml
341+
342+ <!-- config/packages/framework.xml -->
343+ <?xml version =" 1.0" encoding =" UTF-8" ?>
344+ <container xmlns =" http://symfony.com/schema/dic/services"
345+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
346+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
347+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
348+ http://symfony.com/schema/dic/services/services-1.0.xsd
349+ http://symfony.com/schema/dic/symfony
350+ http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
351+
352+ <parameters >
353+ <parameter key =" env(TRUSTED_HOSTS)" >["10.0.0.1", "10.0.0.2"]</parameter >
354+ </parameters >
355+
356+ <framework : config trusted-hosts =" %env(json:TRUSTED_HOSTS)%" />
357+ </container >
358+
359+ .. code-block :: php
360+
361+ // config/packages/framework.php
362+ $container->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]');
363+ $container->loadFromExtension('framework', array(
364+ 'trusted_hosts' => '%env(json:TRUSTED_HOSTS)%',
365+ ));
242366
243367 ``env(resolve:FOO) ``
244368 Replaces the string ``FOO `` by the value of a config parameter with the
245369 same name:
246370
247- .. code -block :: yaml
371+ .. configuration -block ::
248372
249- parameters :
250- env(HOST) : ' 10.0.0.1'
251- env(SENTRY_DSN) : " http://%env(HOST)%/project"
252- sentry :
253- dsn : ' %env(resolve:SENTRY_DSN)%'
373+ .. code-block :: yaml
374+
375+ # config/packages/sentry.yaml
376+ parameters :
377+ env(HOST) : ' 10.0.0.1'
378+ env(SENTRY_DSN) : ' http://%env(HOST)%/project'
379+ sentry :
380+ dsn : ' %env(resolve:SENTRY_DSN)%'
381+
382+ .. code-block :: xml
383+
384+ <!-- config/packages/sentry.xml -->
385+ <?xml version =" 1.0" encoding =" UTF-8" ?>
386+ <container xmlns =" http://symfony.com/schema/dic/services"
387+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
388+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
389+ http://symfony.com/schema/dic/services/services-1.0.xsd" >
390+
391+ <parameters >
392+ <parameter key =" env(HOST)" >10.0.0.1</parameter >
393+ <parameter key =" env(SENTRY_DSN)" >http://%env(HOST)%/project</parameter >
394+ </parameters >
395+
396+ <sentry : config dsn =" %env(resolve:SENTRY_DSN)%" />
397+ </container >
398+
399+ .. code-block :: php
400+
401+ // config/packages/sentry.php
402+ $container->setParameter('env(HOST)', '10.0.0.1');
403+ $container->setParameter('env(SENTRY_DSN)', 'http://%env(HOST)%/project');
404+ $container->loadFromExtension('sentry', array(
405+ 'dsn' => '%env(resolve:SENTRY_DSN)%',
406+ ));
254407
255408 ``env(file:FOO) ``
256409 Returns the contents of a file whose path is the value of the ``FOO `` env var:
257410
258- .. code -block :: yaml
411+ .. configuration -block ::
259412
260- parameters :
261- env(AUTH_FILE) : " ../config/auth.json"
262- google :
263- auth : ' %env(file:AUTH_FILE)%'
413+ .. code-block :: yaml
414+
415+ # config/packages/framework.yaml
416+ parameters :
417+ env(AUTH_FILE) : ' ../config/auth.json'
418+ google :
419+ auth : ' %env(file:AUTH_FILE)%'
420+
421+ .. code-block :: xml
422+
423+ <!-- config/packages/framework.xml -->
424+ <?xml version =" 1.0" encoding =" UTF-8" ?>
425+ <container xmlns =" http://symfony.com/schema/dic/services"
426+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
427+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
428+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
429+ http://symfony.com/schema/dic/services/services-1.0.xsd
430+ http://symfony.com/schema/dic/symfony
431+ http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
432+
433+ <parameters >
434+ <parameter key =" env(AUTH_FILE)" >../config/auth.json</parameter >
435+ </parameters >
436+
437+ <google auth =" %env(file:AUTH_FILE)%" />
438+ </container >
439+
440+ .. code-block :: php
441+
442+ // config/packages/framework.php
443+ $container->setParameter('env(AUTH_FILE)', '../config/auth.json');
444+ $container->loadFromExtension('google', array(
445+ 'auth' => '%env(file:AUTH_FILE)%',
446+ ));
264447
265448 It is also possible to combine any number of processors:
266449
0 commit comments