From df5014399b6c2b793510d94c3dc8ebb1aac7c187 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 1 Jan 2023 16:17:29 +0100 Subject: [PATCH] [DependencyInjection] Allow injecting the current env into php config closures --- service_container.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/service_container.rst b/service_container.rst index f2be38267d6..9eca7a49d1d 100644 --- a/service_container.rst +++ b/service_container.rst @@ -1186,6 +1186,22 @@ If you want to pass the second, you'll need to :ref:`manually wire the service < and the automatically loaded service will be passed - by default - when you type-hint ``SiteUpdateManager``. That's why creating the alias is a good idea. +When using PHP closures to configure your services, it is possible to automatically +inject the current environment value by adding a string argument named ``$env`` to +the closure:: + +.. configuration-block:: + + .. code-block:: php + + // config/packages/my_config.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return function(ContainerConfigurator $configurator, string $env) { + // `$env` is automatically filled in, you can configure your + // services depending on which environment you're on + }; + Learn more ----------