Skip to content

Commit e382dff

Browse files
committed
Update service_subscribers_locators.rst
According to symfony/symfony#34637, `index_by` attribute must be set to make `default_index_method` working
1 parent 504a2a2 commit e382dff

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

service_container/service_subscribers_locators.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ attribute to the locator service defining the name of this custom method:
526526
# ...
527527
528528
App\HandlerCollection:
529-
arguments: [!tagged_locator { tag: 'app.handler', default_index_method: 'myOwnMethodName' }]
529+
arguments: [!tagged_locator { tag: 'app.handler', index_by: 'key', default_index_method: 'myOwnMethodName' }]
530530
531531
.. code-block:: xml
532532
@@ -542,7 +542,7 @@ attribute to the locator service defining the name of this custom method:
542542
<!-- ... -->
543543
544544
<service id="App\HandlerCollection">
545-
<argument type="tagged_locator" tag="app.handler" default-index-method="myOwnMethodName"/>
545+
<argument type="tagged_locator" tag="app.handler" index-by="key" default-index-method="myOwnMethodName"/>
546546
</service>
547547
</services>
548548
</container>
@@ -555,9 +555,12 @@ attribute to the locator service defining the name of this custom method:
555555
return function(ContainerConfigurator $configurator) {
556556
$configurator->services()
557557
->set(App\HandlerCollection::class)
558-
->args([tagged_locator('app.handler', null, 'myOwnMethodName')])
558+
->args([tagged_locator('app.handler', 'key', 'myOwnMethodName')])
559559
;
560560
};
561+
562+
Note since code should not be the place that decides how the locators are going to be used, a configuration key (`key` in the example above) must be set in order this to work. So the custom method may be called as a fallback.
563+
561564

562565
Service Subscriber Trait
563566
------------------------

0 commit comments

Comments
 (0)