Skip to content

Conversation

@jlabedo
Copy link
Contributor

@jlabedo jlabedo commented Jun 5, 2025

Description

Routing for projection event handlers has same behavior as standard event handlers, allowing to use object or named routing.

Considering this event class:

#[NamedEvent(self::NAME)]
class AnEvent
{
    public const NAME = 'test.an_event';

    public function __construct(public readonly string $id)
    {
    }
}

One would be required to listen to event name for the projection:

#[Projection(self::NAME, AnAggregate::STREAM_NAME)]
class AProjection
{
    #[EventHandler(AnEvent::NAME)] // <-- event name required here
    public function onEvent(AnEvent $event): void
    {
    }
}

With this PR, it is optional to declare event name in attribute:

#[Projection(self::NAME, AnAggregate::STREAM_NAME)]
class AProjection
{
    #[EventHandler] // <-- event name is not required
    public function onEvent(AnEvent $event): void
    {
    }
}

Type of change

  • New feature (non-breaking change which adds functionality)

Pull Request Contribution Terms

  • I have read and agree to the contribution terms outlined in CONTRIBUTING.

@jlabedo jlabedo requested review from dgafka and unixslayer June 5, 2025 09:10
{
$className = (string) $className;
foreach ($this->methodAnnotations as $methodAnnotation) {
if (TypeDescriptor::createFromVariable($methodAnnotation)->isCompatibleWith($className)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for this change? Checking compatibility is more complex than only instanceof considering union types, etc. Wouldn't this bring a BC Break?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking compatibility is more complex than only instanceof considering union types, etc. Wouldn't this bring a BC Break?

Is it different when the type is a class ? For other types I understand, but for a class I think instanceof is equivalent.

What was the reason for this change?

I already made this type of change in another class some time ago. Here I get an error so I continued the refactor.

Copy link
Contributor Author

@jlabedo jlabedo Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the only difference I have in mind is if you use a UnionTypeDescriptor, which is a bit awkward to me:
$interfaceToCall->hasMethodAnnotation(TypeDescriptor::create('AClass|BClass'))

I remove this refactor

@jlabedo jlabedo force-pushed the event-routing-for-pdo-event-sourcing branch from 01d332b to 84f4cd5 Compare June 5, 2025 10:10
@jlabedo jlabedo merged commit 7d11a46 into ecotoneframework:main Jun 5, 2025
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants