8000 Minor rewords and formatting fixes · symfony/symfony-docs@aed1607 · GitHub
[go: up one dir, main page]

Skip to content

Commit aed1607

Browse files
Minor rewords and formatting fixes
1 parent e3fe5fe commit aed1607

File tree

1 file changed

+69
-66
lines changed

1 file changed

+69
-66
lines changed

configuration/external_parameters.rst

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ will be used whenever the corresponding environment variable is *not* found:
102102
Environment Variable Processors
103103
-------------------------------
104104

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.
105+
The values of the environment variables are considered strings by def 8000 ault.
106+
However, your code may expect other data types, like integers or booleans.
107+
Symfony solves this problem with *processors*, which modify the contents of the
108+
given environment variables. The following example uses the integer processor to
109+
turn the value of the ``HTTP_PORT`` env var into an integer:
107110

108111
.. configuration-block::
109112

@@ -141,109 +144,111 @@ you will want to have specific types so that they match the types expected by yo
141144
)
142145
));
143146
144-
A number of different types are supported:
147+
Symfony provides the following env var processors:
145148

146149
``env(string:FOO)``
147-
Casts ``FOO`` to a string
150+
Casts ``FOO`` to a string:
148151

149-
.. code-block:: php
152+
.. code-block:: yaml
150153
151-
parameters:
152-
env(SECRET): "some_secret"
153-
framework:
154-
secret: '%env(string:SECRET)%'
154+
parameters:
155+
env(SECRET): "some_secret"
156+
framework:
157+
secret: '%env(string:SECRET)%'
155158
156159
``env(bool:FOO)``
157-
Casts ``FOO`` to a bool
160+
Casts ``FOO`` to a bool:
158161

159-
.. code-block:: php
162+
.. code-block:: yaml
160163
161-
parameters:
162-
env(HTTP_METHOD_OVERRIDE): "true"
163-
framework:
164-
http_method_override: '%env(bool:HTTP_METHOD_OVERRIDE)%'
164+
parameters:
165+
env(HTTP_METHOD_OVERRIDE): "true"
166+
framework:
167+
http_method_override: '%env(bool:HTTP_METHOD_OVERRIDE)%'
165168
166169
``env(int:FOO)``
167-
Casts ``FOO`` to an int
170+
Casts ``FOO`` to an int.
168171

169172
``env(float:FOO)``
170-
Casts ``FOO`` to an float
173+
Casts ``FOO`` to an float.
171174

172175
``env(const:FOO)``
173-
Finds the const value named in ``FOO``
176+
Finds the const value named in ``FOO``:
174177

175-
.. code-block:: php
178+
.. code-block:: yaml
176179
177-
parameters:
178-
env(HEALTH_CHECK_METHOD): "Symfony\Component\HttpFoundation\Request:METHOD_HEAD"
179-
security:
180-
access_control:
181-
- { path: '^/health-check$', methods: '%env(const:HEALTH_CHECK_METHOD)%' }
180+
parameters:
181+
env(HEALTH_CHECK_METHOD): "Symfony\Component\HttpFoundation\Request:METHOD_HEAD"
182+
security:
183+
access_control:
184+
- { path: '^/health-check$', methods: '%env(const:HEALTH_CHECK_METHOD)%' }
182185
183186
``env(base64:FOO)``
184-
Decodes ``FOO`` that is a base64 encoded string
185-
187+
Decodes the content of ``FOO``, which is a base64 encoded string.
188+
186189
``env(json:FOO)``
187-
Decodes ``FOO`` that is a json encoded string into either an array or ``null``
190+
Decodes the content of ``FOO``, which is a JSON encoded string. It returns
191+
either an array or ``null``:
188192

189-
.. code-block:: php
193+
.. code-block:: yaml
194+
195+
parameters:
196+
env(TRUSTED_HOSTS): "['10.0.0.1', '10.0.0.2']"
197+
framework:
198+
trusted_hosts: '%env(json:TRUSTED_HOSTS)%'
190199
191-
parameters:
192-
env(TRUSTED_HOSTS): "['10.0.0.1', '10.0.0.2']"
193-
framework:
194-
trusted_hosts: '%env(json:TRUSTED_HOSTS)%'
195-
196200
``env(resolve:FOO)``
197-
Resolves references in the string ``FOO`` to other parameters
201+
Replaces the string ``FOO`` by the value of a config parameter with the
202+
same name:
198203

199-
.. code-block:: php
204+
.. code-block:: yaml
200205
201-
parameters:
202-
env(HOST): '10.0.0.1'
203-
env(SENTRY_DSN): "http://%env(HOST)%/project"
204-
sentry:
205-
dsn: '%env(resolve:SENTRY_DSN)%'
206+
parameters:
207+
env(HOST): '10.0.0.1'
208+
env(SENTRY_DSN): "http://%env(HOST)%/project"
209+
sentry:
210+
dsn: '%env(resolve:SENTRY_DSN)%'
206211
207212
``env(csv:FOO)``
208-
Decodes ``FOO`` that is a single row of comma seperated values
213+
Decodes the content of ``FOO``, which is a CSV-encoded string:
209214

210-
.. code-block:: php
215+
.. code-block:: yaml
211216
212-
parameters:
213-
env(TRUSTED_HOSTS): "10.0.0.1, 10.0.0.2"
214-
framework:
215-
trusted_hosts: '%env(csv:TRUSTED_HOSTS)%'
217+
parameters:
218+
env(TRUSTED_HOSTS): "10.0.0.1, 10.0.0.2"
219+
framework:
220+
trusted_hosts: '%env(csv:TRUSTED_HOSTS)%'
216221
217222
``env(file:FOO)``
218-
Reads the contents of a file named in ``FOO``
223+
Returns the contents of a file whose path is the value of the ``FOO`` env var:
219224

220-
.. code-block:: php
225+
.. code-block:: yaml
221226
222-
parameters:
223-
env(AUTH_FILE): "auth.json"
224-
google:
225-
auth: '%env(file:AUTH_FILE)%'
226-
227-
It is also possible to combine the processors:
227+
parameters:
228+
env(AUTH_FILE): "../config/auth.json"
229+
google:
230+
auth: '%env(file:AUTH_FILE)%'
228231
229-
``env(json:file:FOO)``
230-
Reads the contents of a file named in ``FOO``, and then decode it from json, resulting in an array or ``null``
232+
It is also possible to combine any number of processors:
231233

232-
.. code-block:: php
234+
.. code-block:: yaml
233235
234236
parameters:
235-
env(AUTH_FILE): "%kernel.root%/auth.json"
237+
env(AUTH_FILE): "%kernel.project_dir%/config/auth.json"
236238
google:
237-
auth: '%env(file:resolve:AUTH_FILE)%'
238-
239+
# 1. gets the value of the AUTH_FILE env var
240+
# 2. replaces the values of any config param to get the config path
241+
# 3. gets the content of the file stored in that path
242+
# 4. JSON-decodes the content of the file and returns it
243+
auth: '%env(json:file:resolve:AUTH_FILE)%'
239244
240245
Custom Environment Variable Processors
241246
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
242247

243-
Its possible to add further processors for environment variables. You just need
244-
to add an implementation of `Symfony\Component\DependencyInjection\EnvVarProcessorInterface`.
245-
246-
.. code-block:: php
248+
It's also possible to add your own processors for environment variables. First,
249+
create a class that implements
250+
:class:`Symfony\\Component\\DependencyInjection\\EnvVarProcessorInterface` and
251+
then, define a service for that class::
247252

248253
class LowercasingEnvVarProcessor implements EnvVarProcessorInterface
249254
{
@@ -269,8 +274,6 @@ to add an implementation of `Symfony\Component\DependencyInjection\EnvVarProcess
269274
}
270275
}
271276

272-
273-
274277
.. _configuration-env-var-in-prod:
275278

276279
Configuring Environment Variables in Production

0 commit comments

Comments
 (0)
0