Skip to content

default_index_method not handled without index_by #34637

@codegain

Description

@codegain

Symfony version(s) affected: 4.3.8

Description
If "default_index_method" is used and "index_by" is omitted, the tagged services are not indexed.

How to reproduce

  1. Use _instanceof in your services.yaml to attach a tag to an interface
_instanceof:
    App\Test\TagTestInterface:
        tags: ['app.list']
  1. Add a class to your services.yaml and inject the tagged list:
TestTagList:
    arguments: [!tagged { tag: app.list } ]
  1. Use the "default_index_method" as described here (https://symfony.com/doc/current/service_container/service_subscribers_locators.html#indexing-the-collection-of-services)
TestTagList:
    arguments: [!tagged { tag: app.list, default_index_method: 'getTest' } ]
  1. The injected tagged list will not have been indexed.

Possible Solution
You can add
index_by: 'somestring'
in order for "default_index_method" to be working.

TestTagList:
    arguments: [!tagged { tag: app.list, index_by: 'somestring', default_index_method: 'getTest' } ]

Maybe this is not a bug but just not clear enough in the docs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions