Skip to content

Commit df50143

Browse files
[DependencyInjection] Allow injecting the current env into php config closures
1 parent 666ee59 commit df50143

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

service_container.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,22 @@ If you want to pass the second, you'll need to :ref:`manually wire the service <
11861186
and the automatically loaded service will be passed - by default - when you type-hint
11871187
``SiteUpdateManager``. That's why creating the alias is a good idea.
11881188

1189+
When using PHP closures to configure your services, it is possible to automatically
1190+
inject the current environment value by adding a string argument named ``$env`` to
1191+
the closure::
1192+
1193+
.. configuration-block::
1194+
1195+
.. code-block:: php
1196+
1197+
// config/packages/my_config.php
1198+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1199+
1200+
return function(ContainerConfigurator $configurator, string $env) {
1201+
// `$env` is automatically filled in, you can configure your
1202+
// services depending on which environment you're on
1203+
};
1204+
11891205
Learn more
11901206
----------
11911207

0 commit comments

Comments
 (0)