From 52f80e97ab9fe323d32e79abf2a716a8f6e04284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Sun, 10 Jul 2022 22:25:06 +0200 Subject: [PATCH] [DependencyInjection] Add shuffle env var processor documentation Closes #16961 --- configuration/env_var_processors.rst | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/configuration/env_var_processors.rst b/configuration/env_var_processors.rst index 35a247dd6fa..feea91dd3d4 100644 --- a/configuration/env_var_processors.rst +++ b/configuration/env_var_processors.rst @@ -378,6 +378,59 @@ Symfony provides the following env var processors: $container->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2'); $framework->trustedHosts(env('TRUSTED_HOSTS')->csv()); }; +``env(shuffle:FOO)`` + Randomly shuffles values of ``FOO``, which is an array. + Usable when combining with other processors, as array is a prerequisite. + + .. configuration-block:: + + .. code-block:: yaml + + # config/packages/framework.yaml + parameters: + env(REDIS_NODES): "127.0.0.1:6380,127.0.0.1:6381" + services: + RedisCluster: + class: RedisCluster + arguments: [null, "%env(shuffle:csv:REDIS_NODES)%"] + + .. code-block:: xml + + + + + + + redis://127.0.0.1:6380,redis://127.0.0.1:6381 + + + + + null + %env(shuffle:csv:REDIS_NODES)% + + + + + .. code-block:: php + + // config/services.php + use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; + + return static function (ContainerConfigurator $configurator): void { + $container = $configurator->services() + ->set(\RedisCluster::class, \RedisCluster::class)->args([null, '%env(shuffle:csv:REDIS_NODES)%']); + }; + +.. versionadded:: 6.2 + + The ``env(shuffle:...)`` env var processor was introduced in Symfony 6.2. ``env(file:FOO)`` Returns the contents of a file whose path is the value of the ``FOO`` env var: