From 49e2405e6b5e3639e345709634a99e54a0c374b0 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 8 Jan 2023 20:05:48 +0100 Subject: [PATCH] [DependencyInjection] Add #[AsTaggedItem] documentation --- service_container/tags.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/service_container/tags.rst b/service_container/tags.rst index 9de74dc922c..7196d5fea93 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -897,3 +897,25 @@ array element. For example, to retrieve the ``handler_two`` handler:: ]) ; }; + +The #[AsTaggedItem] attribute +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +It is possible to define both the priority and the index of a tagged +item thanks to the ``#[AsTaggedItem]`` attribute. This attribute must +be used directly on the class of the service you want to configure:: + + // src/Handler/One.php + namespace App\Handler; + + use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; + + #[AsTaggedItem(index: 'handler_one', priority: 10)] + class One + { + // ... + } + +.. versionadded:: 5.3 + + The ``#[AsTaggedItem]`` attribute was introduced in Symfony 5.3 and requires PHP 8.