Skip to content

Commit c658aca

Browse files
committed
minor #17639 [DependencyInjection] Allow injecting the current env into php config closures (alexandre-daubois)
This PR was merged into the 6.2 branch. Discussion ---------- [DependencyInjection] Allow injecting the current env into php config closures Resolves #17367 Gave this a try, not exactly sure of where this should be located in the documentation. `Explicitly Configuring Services and Arguments` seemed the good section to me. If it's not, I'll be happy to do required updates! 👍 Commits ------- df50143 [DependencyInjection] Allow injecting the current env into php config closures
2 parents e7ff39e + df50143 commit c658aca

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
@@ -1280,6 +1280,22 @@ If you want to pass the second, you'll need to :ref:`manually wire the service <
12801280
and the automatically loaded service will be passed - by default - when you type-hint
12811281
``SiteUpdateManager``. That's why creating the alias is a good idea.
12821282

1283+
When using PHP closures to configure your services, it is possible to automatically
1284+
inject the current environment value by adding a string argument named ``$env`` to
1285+
the closure::
1286+
1287+
.. configuration-block::
1288+
1289+
.. code-block:: php
1290+
1291+
// config/packages/my_config.php
1292+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1293+
1294+
return function(ContainerConfigurator $configurator, string $env) {
1295+
// `$env` is automatically filled in, you can configure your
1296+
// services depending on which environment you're on
1297+
};
1298+
12831299
Learn more
12841300
----------
12851301

0 commit comments

Comments
 (0)