Skip to content

Commit 7dd3c01

Browse files
committed
[DependencyInjection] Add shuffle env var processor documentation
Closes #16961
1 parent 8896d7a commit 7dd3c01

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

configuration/env_var_processors.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,58 @@ Symfony provides the following env var processors:
378378
$container->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2');
379379
$framework->trustedHosts(env('TRUSTED_HOSTS')->csv());
380380
};
381+
``env(shuffle:FOO)``
382+
Randomly shuffles values of ``FOO``, which is an array.
383+
Usable when combining with other processors, as array is a prerequisite.
384+
385+
.. configuration-block::
386+
387+
.. code-block:: yaml
388+
389+
# config/packages/framework.yaml
390+
parameters:
391+
env(REDIS_NODES): "127.0.0.1:6380,127.0.0.1:6381"
392+
services:
393+
RedisCluster:
394+
arguments: [null, "%env(shuffle:csv:REDIS_NODES)%"]
395+
396+
.. code-block:: xml
397+
398+
<!-- config/packages/framework.xml -->
399+
<?xml version="1.0" encoding="UTF-8" ?>
400+
<container xmlns="http://symfony.com/schema/dic/services"
401+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
402+
xmlns:framework="http://symfony.com/schema/dic/symfony"
403+
xsi:schemaLocation="http://symfony.com/schema/dic/services
404+
https://symfony.com/schema/dic/services/services-1.0.xsd
405+
http://symfony.com/schema/dic/symfony
406+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
407+
408+
<parameters>
409+
<parameter key="env(REDIS_NODES)">redis://127.0.0.1:6380,redis://127.0.0.1:6381</parameter>
410+
</parameters>
411+
412+
<services>
413+
<service id="RedisCluster" class="RedisCluster">
414+
<argument>null</argument>
415+
<argument>%env(shuffle:csv:REDIS_NODES)%</argument>
416+
</service>
417+
</services>
418+
</container>
419+
420+
.. code-block:: php
421+
422+
// config/services.php
423+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
424+
425+
return static function (ContainerConfigurator $configurator): void {
426+
$container = $configurator->services()
427+
->set(\RedisCluster::class, \RedisCluster::class)->args([null, '%env(shuffle:csv:REDIS_NODES)%']);
428+
};
429+
430+
.. versionadded:: 6.2
431+
432+
The ``env(shuffle:...)`` env var processor was introduced in Symfony 6.2.
381433

382434
``env(file:FOO)``
383435
Returns the contents of a file whose path is the value of the ``FOO`` env var:

0 commit comments

Comments
 (0)