Skip to content

[Messenger] Support extending AsMessageHandler attribute #52898

@RobertMe

Description

@RobertMe

Description

The AsMessageHandler attribute has some options which would be pretty common / supplied by numerous locations using the attribute. For example the $bus argument, if you define multiple buses you would most likely want to define this argument for all (or all except one, the default, bus type). Being able to extend the AsMessageHandler would make this a lot simpler.

Currently one can actually extend the class. But this doesn't work as the AttributeAutoconfigurationPass doesn't handle inheritance. Something which it IMO also shouldn't do by default. But in some cases there are attribute where it really makes sense to allow inheritance.

In case this wouldn't be accepted, it is my opinion that the attribute class, i.e. AsMessageHandler should be final, as extending it actually doesn't work / extending it only has the meaning of inheriting the properties, but not the behavior (autoconfiguration) applied to the attribute.

Example

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class AsCommandHandler extends AsMessageHandler
{
    public function __construct(
        ?string $fromTransport = null,
        ?string $handles = null,
        ?string $method = null,
        int $priority = 0,
    ) {
        parent::__construct('command.bus', $fromTransport, $handles, $method, $priority);
    }
}

in combination with

#[AsCommandHandler]
class FooHandler
{
  ...
}

#[AsCommandHandler]
class BarHandler
{
  ...
}

Instead of the current:

#[AsMessageHandler('command.bus')]
class FooHandler
{
  ...
}

#[AsMessageHandler('command.bus')]
class BarHandler
{
  ...
}

(obviously having multiple As...Handler attributes which use different $bus arguments)

Metadata

Metadata

Assignees

No one assigned

    Labels

    MessengerRFCRFC = 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