Skip to content

Commit 6693f26

Browse files
committed
feature #7983 [DI] Automatically applying a tag to all services implementing an int… (danut007ro)
This PR was squashed before being merged into the 3.3 branch (closes #7983). Discussion ---------- [DI] Automatically applying a tag to all services implementing an int… …erface Commits ------- c31e24c Create tags.rst e5b1758 Update tags.rst cb545ff [DI] Automatically applying a tag to all services implementing an interface
2 parents dddafbf + c31e24c commit 6693f26

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

service_container/tags.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ then some tags are automatically applied for you. That's true for the ``twig.ext
7070
tag: the container sees that your class extends ``Twig_Extension`` (or more accurately,
7171
that it implements ``Twig_ExtensionInterface``) and adds the tag for you.
7272

73+
.. tip::
74+
75+
To apply a tag to all your autoconfigured services extending a class or an
76+
interface, call :method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerForAutoconfiguration`
77+
method in an :doc:`extension </bundles/extension>` or from your kernel::
78+
79+
// app/AppKernel.php
80+
class AppKernel extends Kernel
81+
{
82+
// ...
83+
84+
protected function build(ContainerBuilder $container)
85+
{
86+
$container->registerForAutoconfiguration(CustomInterface::class)
87+
->addTag('app.custom_tag')
88+
;
89+
}
90+
}
91+
7392
Creating custom Tags
7493
--------------------
7594

0 commit comments

Comments
 (0)