Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CatchAllEventListenerInterface #259

Open
bwaidelich opened this issue Feb 11, 2020 · 1 comment · May be fixed by #260
Open

CatchAllEventListenerInterface #259

bwaidelich opened this issue Feb 11, 2020 · 1 comment · May be fixed by #260
Labels

Comments

@bwaidelich
Copy link
Member

@bwaidelich bwaidelich commented Feb 11, 2020

Currently it's cumbersome to create a listener/projector that is invoked for all event types:

<?php
final class SomeLogProjector implements ProjectorInterface
{
    public function whenSomeEventType1(SomeEventType1 $event, RawEvent $rawEvent): void
    {
        $this->addToEventLog($rawEvent)
    }

    public function whenSomeEventType2(SomeEventType2 $event, RawEvent $rawEvent): void
    {
        $this->addToEventLog($rawEvent)
    }

    // ...
}

With the BeforeInvokeInterface things can be centralized, but the corresponding when*() methods still have to be implemented in order for the listener to be invoked:

<?php
final class SomeLogProjector implements ProjectorInterface, BeforeInvokeInterface
{

    public function beforeInvoke(EventEnvelope $eventEnvelope): void
    {
        $this->addToEventLog($eventEnvelope->getRawEvent())
    }

    public function whenSomeEventType1(SomeEventType1 $_): void
    {
        // this method is required
    }

    public function whenSomeEventType2(SomeEventType2 $_): void
    {
        // this method is required
    }

    // ...
}

To make these cases easier we should provide an additional (marker) interface that informs the framework that this listener should be invoked for all events:

<?php
final class SomeLogProjector implements ProjectorInterface, CatchAllEventListener, BeforeInvokeInterface
{

    public function beforeInvoke(EventEnvelope $eventEnvelope): void
    {
        $this->addToEventLog($eventEnvelope->getRawEvent())
    }

    public function whenSomeEventType2(SomeEventType2 $event): void
    {
        // this method CAN still be implemented and will be invoked for the corresponding event type
    }

    // ...
}
@bwaidelich bwaidelich added the 🐞 Bug label Feb 11, 2020
@bwaidelich

This comment has been minimized.

Copy link
Member Author

@bwaidelich bwaidelich commented Feb 12, 2020

bwaidelich added a commit to bwaidelich/Neos.EventSourcing that referenced this issue Feb 21, 2020
@bwaidelich bwaidelich linked a pull request that will close this issue Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.