8000 - · symfony/symfony-docs@3722202 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3722202

Browse files
committed
-
1 parent 8d209db commit 3722202

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

service_container.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,31 @@ For a full list of *all* possible services in the container, run:
688688
689689
$ php bin/console debug:container
690690
691+
Remove Services
692+
---------------
693+
694+
A service can be removed from the service container if needed. This is useful
695+
for example to make a service unavailable in some :ref:`configuration environment <configuration-environments>`
696+
(e.g. in the ``test`` environment):
697+
698+
.. configuration-block::
699+
700+
.. code-block:: php
701+
702+
// config/services_test.php
703+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
704+
705+
use App\RemovedService;
706+
707+
return function(ContainerConfigurator $containerConfigurator) {
708+
$services = $containerConfigurator->services();
709+
710+
$services->remove(RemovedService::class);
711+
};
712+
713+
Now, the container will not contain the ``App\RemovedService`` in the ``test``
714+
environment.
715+
691716
.. _container_closure-as-argument:
692717

693718
Injecting a Closure as an Argument

0 commit comments

Comments
 (0)
0