Skip to content

Commit 16b2bca

Browse files
committed
minor #17342 [DependencyInjection] Typo on how default defaultIndexMethod work (Kleinast)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Typo on how default defaultIndexMethod work Following the documentation, I was trying the static method getDefaultIndexName() to have named tagged service and it didn't work. I looked at the code [here](https://github.com/symfony/symfony/blob/v5.4.1/src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php#L44) in how I understand it, you have to declare the index_by attribute to be able to use the getDefault****Name() method. I tryed to improve the documentation, but I think it could be better explained that what I did. It is the same logique for the getDefault***Priority() method. Commits ------- 720e9f7 [DependencyInjection] Typo on how default defaultIndexMethod work
2 parents 00ac4ce + 720e9f7 commit 16b2bca

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

service_container/tags.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,17 +921,29 @@ array element. For example, to retrieve the ``handler_two`` handler::
921921

922922
.. tip::
923923

924-
Just like the priority, you can also implement a static
925-
``getDefaultIndexName()`` method in the handlers and omit the
924+
Just like the priority, if you set the attribute (``index_by``) on the :tagged_iterator, you can also implement a static
925+
``getDefault(``index_by``)Name()`` method in the handlers and omit the
926926
index attribute (``key``)::
927+
928+
929+
.. code-block:: yaml
930+
931+
# config/services.yaml
932+
services:
933+
# ...
934+
935+
App\HandlerCollection:
936+
arguments: [!tagged_iterator { tag: 'app.handler', index_by: 'handler' }]
937+
938+
.. code-block:: php
927939
928940
// src/Handler/One.php
929941
namespace App\Handler;
930942
931943
class One
932944
{
933945
// ...
934-
public static function getDefaultIndexName(): string
946+
public static function getDefaultHandlerName(): string
935947
{
936948
return 'handler_one';
937949
}

0 commit comments

Comments
 (0)