Skip to content

[DI] Improve an example about automatic tags and bundles #13305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions service_container/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 </bundles/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
Expand All @@ -133,6 +134,22 @@ method in an :doc:`extension </bundles/extension>` or from your kernel::
}
}

In a Symfony bundle, call this method in the ``load()`` method of the
:doc:`bundle extension class </bundles/extension>`::

// 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
--------------------

Expand Down