Skip to content

Enable TaggedLocator extension in AutowirePass #50630

@KerianMM

Description

@KerianMM

Description

I want to create some collection of services like workflows, but I can't extend TaggedLocator to don't repeat the declaration everywhere.

The AutowirePass::autowireMethod filters on TaggedIterator, TaggedLocator, Autowire and MapDecorated, so my custom attribute is not processed.

I don't know the best way to address this, but without this filter, my ServiceLocator is correctly autowired.
Maybe an interface on attributes for autowiring ? Or modify this AutowirePass::autowireMethod filter ?

Example

Attribute extension example

use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;

#[\Attribute(\Attribute::TARGET_PARAMETER)]
class WorkflowStateMachineLocator extends TaggedLocator
{
    public function __construct(array|string $exclude = [])
    {
        parent::__construct(
            tag: 'workflow.state_machine',
            indexAttribute: 'name',
            exclude: $exclude,
        );
    }
}

Usage

use Symfony\Component\DependencyInjection\ServiceLocator;

final class MyClass
{
    public function __construct(
        #[WorkflowStateMachineLocator]
        private ServiceLocator $workflows,
    ) {
    }

    // ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions