From 1f4540d10a083f73ff32f9885244f54ab6a67c5f Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Tue, 2 Aug 2022 22:51:55 +0200 Subject: [PATCH] [DependencyInjection] Document remove() method on the PHP configurator --- service_container/remove.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 service_container/remove.rst diff --git a/service_container/remove.rst b/service_container/remove.rst new file mode 100644 index 00000000000..e8e82114299 --- /dev/null +++ b/service_container/remove.rst @@ -0,0 +1,26 @@ +.. index:: + single: Service Container; Remove Service + +How to Remove a Service +======================= + +A service can be removed from the service container if needed +(for instance in the test or a specific environment): + +.. configuration-block:: + + .. code-block:: php + + // config/services_test.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + use App\RemovedService; + + return function(ContainerConfigurator $configurator) { + $services = $configurator->services(); + + $services->remove(RemovedService::class); + }; + +Now, the container will not contain the ``App\RemovedService`` +in the test environment.