Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c21325

Browse files
committed
EnvVar processors
1 parent 9e073fe commit 9c21325

File tree

3 files changed

+56
-38
lines changed

3 files changed

+56
-38
lines changed

configuration/env_var_processors.rst

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ processor to turn the value of the ``HTTP_PORT`` env var into an integer:
4444
.. code-block:: php
4545
4646
// config/packages/framework.php
47-
$container->loadFromExtension('framework', [
48-
'router' => [
49-
'http_port' => '%env(int:HTTP_PORT)%',
50-
],
51-
]);
47+
use Symfony\Config\FrameworkConfig;
48+
49+
return static function (FrameworkConfig $framework) {
50+
$framework->router()
51+
->httpPort('%env(int:HTTP_PORT)%')
52+
;
53+
};
5254
5355
Built-In Environment Variable Processors
5456
----------------------------------------
@@ -90,10 +92,13 @@ Symfony provides the following env var processors:
9092
.. code-block:: php
9193
9294
// config/packages/framework.php
93-
$container->setParameter('env(SECRET)', 'some_secret');
94-
$container->loadFromExtension('framework', [
95-
'secret' => '%env(string:SECRET)%',
96-
]);
95+
use Symfony\Component\DependencyInjection\ContainerBuilder;
96+
use Symfony\Config\FrameworkConfig;
97+
98+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
99+
$container->setParameter('env(SECRET)', 'some_secret');
100+
$framework->secret('%env(string:SECRET)%');
101+
};
97102
98103
``env(bool:FOO)``
99104
Casts ``FOO`` to a bool (``true`` values are ``'true'``, ``'on'``, ``'yes'``
@@ -131,10 +136,13 @@ Symfony provides the following env var processors:
131136
.. code-block:: php
132137
133138
// config/packages/framework.php
134-
$container->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true');
135-
$container->loadFromExtension('framework', [
136-
'http_method_override' => '%env(bool:HTTP_METHOD_OVERRIDE)%',
137-
]);
139+
use Symfony\Component\DependencyInjection\ContainerBuilder;
140+
use Symfony\Config\FrameworkConfig;
141+
142+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
143+
$container->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true');
144+
$framework->httpMethodOverride('%env(bool:HTTP_METHOD_OVERRIDE)%');
145+
};
138146
139147
``env(not:FOO)``
140148

@@ -269,10 +277,13 @@ Symfony provides the following env var processors:
269277
.. code-block:: php
270278
271279
// config/packages/framework.php
272-
$container->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]');
273-
$container->loadFromExtension('framework', [
274-
'trusted_hosts' => '%env(json:TRUSTED_HOSTS)%',
275-
]);
280+
use Symfony\Component\DependencyInjection\ContainerBuilder;
281+
use Symfony\Config\FrameworkConfig;
282+
283+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
284+
$container->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]');
285+
$framework->trustedHosts('%env(json:TRUSTED_HOSTS)%');
286+
};
276287
277288
``env(resolve:FOO)``
278289
If the content of ``FOO`` includes container parameters (with the syntax
@@ -353,10 +364,13 @@ Symfony provides the following env var processors:
353364
.. code-block:: php
354365
355366
// config/packages/framework.php
356-
$container->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2');
357-
$container->loadFromExtension('framework', [
358-
'trusted_hosts' => '%env(csv:TRUSTED_HOSTS)%',
359-
]);
367+
use Symfony\Component\DependencyInjection\ContainerBuilder;
368+
use Symfony\Config\FrameworkConfig;
369+
370+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
371+
$container->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2');
372+
$framework->trustedHosts('%env(csv:TRUSTED_HOSTS)%');
373+
};
360374
361375
``env(file:FOO)``
362376
Returns the contents of a file whose path is the value of the ``FOO`` env var:

configuration/secrets.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,15 @@ The secrets system is enabled by default and some of its behavior can be configu
305305
.. code-block:: php
306306
307307
// config/packages/framework.php
308-
$container->loadFromExtension('framework', [
309-
'secrets' => [
310-
// 'vault_directory' => '%kernel.project_dir%/config/secrets/%kernel.environment%',
311-
// 'local_dotenv_file' => '%kernel.project_dir%/.env.%kernel.environment%.local',
312-
// 'decryption_env_var' => 'base64:default::SYMFONY_DECRYPTION_SECRET',
313-
],
314-
]);
308+
use Symfony\Config\FrameworkConfig;
309+
310+
return static function (FrameworkConfig $framework) {
311+
$framework->secrets()
312+
// ->vaultDirectory('%kernel.project_dir%/config/secrets/%kernel.environment%')
313+
// ->localDotenvFile('%kernel.project_dir%/.env.%kernel.environment%.local')
314+
// ->decryptionEnvVar('base64:default::SYMFONY_DECRYPTION_SECRET')
315+
;
316+
};
315317
316318
317319
.. _`libsodium`: https://pecl.php.net/package/libsodium

deployment/proxies.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ and what headers your reverse proxy uses to send information:
6868
.. code-block:: php
6969
7070
// config/packages/framework.php
71-
use Symfony\Component\HttpFoundation\Request;
72-
73-
$container->loadFromExtension('framework', [
74-
// the IP address (or range) of your proxy
75-
'trusted_proxies' => '192.0.0.1,10.0.0.0/8',
76-
// trust *all* "X-Forwarded-*" headers (the ! prefix means to not trust those headers)
77-
'trusted_headers' => ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port'],
78-
// or, if your proxy instead uses the "Forwarded" header
79-
'trusted_headers' => ['forwarded'],
80-
]);
71+
use Symfony\Config\FrameworkConfig;
72+
73+
return static function (FrameworkConfig $framework) {
74+
$framework
75+
// the IP address (or range) of your proxy
76+
->trustedProxies('192.0.0.1,10.0.0.0/8')
77+
// trust *all* "X-Forwarded-*" headers (the ! prefix means to not trust those headers)
78+
->trustedHeaders(['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port'])
79+
// or, if your proxy instead uses the "Forwarded" header
80+
->trustedHeaders(['forwarded'])
81+
;
82+
};
8183
8284
.. deprecated:: 5.2
8385

0 commit comments

Comments
 (0)