8000 [RFC] EventSubscriber attribute · Issue #47015 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[RFC] EventSubscriber attribute #47015
Closed
Closed
@94noni

Description

@94noni

Description

RFC - Feature Request - EventSubscriber attribute

Opening this issue to gather feedbacks

Adding a new attribute AsEventSubscriber (mimic of AsCommand) for configuring EventSubscriber classes/methodes

Example

Before:

final class ProductSyncSubscriber implements EventSubscriberInterface
{
    public function __construct(private readonly Manager $manager) {}

    public static function getSubscribedEvents(): array
    {
        return [
            ProductUpdatedEvent::class => 'onProductUpdated',
        ];
    }

    public function onProductUpdated(ProductUpdatedEvent $productUpdatedEvent): void
    {
        $this->manager->sync($productUpdatedEvent->getProductId());
    }
}

After:

final class ProductSyncSubscriber
{
    public function __construct(private readonly Manager $manager) {}
    
    #[AsEventSubscriber(event: ProductUpdatedEvent, priority: 11)]
    public function onProductUpdated(ProductUpdatedEvent $productUpdatedEvent): void
    {
        $this->manager->sync($productUpdatedEvent->getProductId());
    }
}

  • Then either implement new empty interface or extends empty class to autoconfigure
  • Or register like controller as service

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0