Skip to content

Commit 8976844

Browse files
committed
minor #13305 [DI] Improve an example about automatic tags and bundles (javiereguiluz)
This PR was merged into the 4.4 branch. Discussion ---------- [DI] Improve an example about automatic tags and bundles I just needed this inside a bundle ... and the example only shows a Symfony app ... so this was confusing to me. But if you prefer to not expand this example, it's OK to close this. Thanks! Commits ------- 6ab0fdd [DI] Improve an example about automatic tags and bundles
2 parents e2f6e7e + 6ab0fdd commit 8976844

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

service_container/tags.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ If you want to apply tags automatically for your own services, use the
117117
118118
119119
For more advanced needs, you can define the automatic tags using the
120-
:method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerForAutoconfiguration`
121-
method in an :doc:`extension </bundles/extension>` or from your kernel::
120+
:method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerForAutoconfiguration` method.
121+
122+
In a Symfony application, call this method in your kernel class::
122123

123124
// src/Kernel.php
124125
class Kernel extends BaseKernel
@@ -133,6 +134,22 @@ method in an :doc:`extension </bundles/extension>` or from your kernel::
133134
}
134135
}
135136

137+
In a Symfony bundle, call this method in the ``load()`` method of the
138+
:doc:`bundle extension class </bundles/extension>`::
139+
140+
// src/DependencyInjection/MyBundleExtension.php
141+
class MyBundleExtension extends Extension
142+
{
143+
// ...
144+
145+
public function load(array $configs, ContainerBuilder $container)
146+
{
147+
$container->registerForAutoconfiguration(CustomInterface::class)
148+
->addTag('app.custom_tag')
149+
;
150+
}
151+
}
152+
136153
Creating custom Tags
137154
--------------------
138155

0 commit comments

Comments
 (0)