@@ -63,24 +63,63 @@ automatically applied for you. That's true for the ``twig.extension`` tag: the
6363container sees that your class extends ``AbstractExtension `` (or more accurately,
6464that it implements ``ExtensionInterface ``) and adds the tag for you.
6565
66- ..tip ::
66+ If you want to apply tags automatically for your own services, use the
67+ ``_instanceof `` option::
6768
68- To apply a tag to all your autoconfigured services extending a class or implementing an
69- interface, call the:method: `Symfony\\ Component\\ DependencyInjection\\ ContainerBuilder::registerForAutoconfiguration `
70- method in an:doc: `extension </bundles/extension >` or from your kernel::
69+ ..configuration-block ::
7170
72- // src/Kernel.php
73- class Kernel extends Kernel
74- {
75- // ...
71+ ..code-block ::yaml
7672
77- protected function build(ContainerBuilder $container)
78- {
79- $container->registerForAutoconfiguration(CustomInterface::class)
80- ->addTag('app.custom_tag')
81- ;
82- }
73+ # config/services.yaml
74+ services :
75+ # this config only applies to the services created by this file
76+ _instanceof :
77+ # services whose classes are instances of CustomInterface will be tagged automatically
78+ App\Security\CustomInterface :
79+ tags :['app.custom_tag']
80+ # ...
81+
82+ ..code-block ::xml
83+
84+ <!-- config/services.xml-->
85+ <?xml version =" 1.0" encoding =" utf-8" ?>
86+ <container xmlns =" http://symfony.com/schema/dic/services" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
87+ <services >
88+ <!-- this config only applies to the services created by this file-->
89+ <instanceof id =" App\Security\CustomInterface" autowire =" true" >
90+ <!-- services whose classes are instances of CustomInterface will be tagged automatically-->
91+ <tag name =" app.custom_tag" />
92+ </instanceof >
93+ </services >
94+ </container >
95+
96+ ..code-block ::php
97+
98+ // config/services.php
99+ use App\Security\CustomInterface;
100+ // ...
101+
102+ // services whose classes are instances of CustomInterface will be tagged automatically
103+ $container->registerForAutoconfiguration(CustomInterface::class)
104+ ->addTag('app.custom_tag')
105+ ->setAutowired(true);
106+
107+ For more advanced needs, you can define the automatic tags using the
108+ :method: `Symfony\\ Component\\ DependencyInjection\\ ContainerBuilder::registerForAutoconfiguration `
109+ method in an:doc: `extension </bundles/extension >` or from your kernel::
110+
111+ // src/Kernel.php
112+ class Kernel extends BaseKernel
113+ {
114+ // ...
115+
116+ protected function build(ContainerBuilder $container)
117+ {
118+ $container->registerForAutoconfiguration(CustomInterface::class)
119+ ->addTag('app.custom_tag')
120+ ;
83121 }
122+ }
84123
85124Creating custom Tags
86125--------------------