Skip to content

Commit e5b1758

Browse files
authored
Update tags.rst
1 parent cb545ff commit e5b1758

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

service_container/tags.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,24 @@ 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-
In order to have a tag automatically applied to all your services that implement an interface,
74-
you should create an extension following the steps described in :doc:`/bundles/extension`,
75-
then in the ``load()`` method call ``registerForAutoconfiguration()`` and apply your tag::
76-
77-
// src/AppBundle/DependencyInjection/AppExtension.php
73+
.. tip::
7874

79-
// ...
80-
public function load(array $configs, ContainerBuilder $container)
81-
{
82-
$container->registerForAutoconfiguration(CustomInterface::class)
83-
->addTag('app.custom_tag')
84-
;
85-
}
75+
To apply a tag to all your autoconfigured services extending a class or an
76+
interface, call ``ContainerBuilder::registerForAutoconfiguration()`` in an
77+
: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+
}
8691

8792
Creating custom Tags
8893
--------------------

0 commit comments

Comments
 (0)