Skip to content

[Messenger] Can't repeat #[AsMessageHandler] to replicate previous functionality of deprecated MessageSubscriberInterface #50267

@adrolter

Description

@adrolter

Symfony version(s) affected

6.2.x

Description

Using the MessageSubscriberInterface it was possible to declare multiple handlers pointing to different methods of a class, without the implementation of those methods being directly defined in that class — e.g.:

class FooHandler 
    extends AbstractHandler // <- contains implementations
    implements MessageSubscriberInterface
{
    public function getHandledMessages(): iterable
    {
        yield SomeMessage::class => ['method' => 'someMethodFromAbstractParent'];
        yield SomeOtherMessage::class => ['method' => 'someOtherMethodFromAbstractParent'];
    }
}

Unless I'm missing something obvious this is no longer possible, as #[AsMessageHandler] would have to be repeatable on the class itself to replicate this functionality, but the attribute lacks the IS_REPEATABLE flag.

Possible Solution

Add the \Attribute::IS_REPEATABLE flag to the existing flags on the attribute, supporting the following syntax:

#[AsMessageHandler(
    handles: SomeMessage::class,
    method: 'someMethodFromAbstractParent',
    priority: 10,
)]
#[AsMessageHandler(
    handles: SomeOtherMessage::class,
    method: 'someOtherMethodFromAbstractParent',
    priority: 10,
)]
class FooHandler 
    extends AbstractHandler // <- contains implementations
{
}

This seems to resolve the issue, and I'm happy to submit a PR if it would be accepted.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy