From 6ab0fdde99f67cde4011ecdd3cf47f9460676d7a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 4 Mar 2020 17:34:23 +0100 Subject: [PATCH] [DI] Improve an example about automatic tags and bundles --- service_container/tags.rst | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/service_container/tags.rst b/service_container/tags.rst index 8fbd7d5671c..ff56d90c73f 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -117,8 +117,9 @@ If you want to apply tags automatically for your own services, use the For more advanced needs, you can define the automatic tags using the -:method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerForAutoconfiguration` -method in an :doc:`extension ` or from your kernel:: +:method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerForAutoconfiguration` method. + +In a Symfony application, call this method in your kernel class:: // src/Kernel.php class Kernel extends BaseKernel @@ -133,6 +134,22 @@ method in an :doc:`extension ` or from your kernel:: } } +In a Symfony bundle, call this method in the ``load()`` method of the +:doc:`bundle extension class `:: + + // src/DependencyInjection/MyBundleExtension.php + class MyBundleExtension extends Extension + { + // ... + + public function load(array $configs, ContainerBuilder $container) + { + $container->registerForAutoconfiguration(CustomInterface::class) + ->addTag('app.custom_tag') + ; + } + } + Creating custom Tags --------------------