-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
DependencyInjectionFeatureHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.
Description
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
Labels
DependencyInjectionFeatureHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.