Closed
Description
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.