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

[EventDispatcher] Listeners per events which implement some interface #52145

Closed
alebedev80 opened this issue Oct 18, 2023 · 7 comments
Closed

Comments

@alebedev80
Copy link
Contributor

alebedev80 commented Oct 18, 2023

Description

I need event subscriber which listen any event which implements some interface.

Example

The LoggableEventSubscriber::onLoggableEvent() will be called per EventFoo and EventBar

interface LoggableEvent {}
class EventFoo implements LoggableEvent{}
class EventBar implements LoggableEvent{}
class EventBaz {}
final readonly class LoggableEventSubscriber implements EventSubscriberInterface
{

    public static function getSubscribedEvents(): array
    {
        return [
            LoggableEvent::class => [['onLoggableEvent, 1000]],
        ];
    }

   public function onLoggableEvent() {
       ....
   }
@stof
Copy link
Member

stof commented Oct 19, 2023

Supporting that would probably have a non-negligeable performance impact (for all users of the components, not just when this feature is used) because this requires changing the loading of listeners to not be a O(1) lookup in a hashmap anymore.

@alebedev80
Copy link
Contributor Author

@stof of course, the performance of such a dispatcher will be worse, but the organization of the code and its support for some tasks will be greatly improved. I think it makes sense to make a separate class of the dispatcher, which the user will connect independently if necessary.

@abidkhan484
Copy link

abidkhan484 commented Oct 19, 2023

Dear Concern,

If the feature will be accepted by the maintainers, I would like to try to implement the feature.

Regards,
Abid

@mihai-stancu
Copy link

+1

@xabbuh
Copy link
Member

xabbuh commented Oct 24, 2023

Given that the proposed event dispatcher would have a worse performance compared to the optimized one we already have I would be rather reluctant to add this one to the core. IMO such a class would fit nicely in a third-party package that could make the upsides and downsides of the class compared to Symfony's one quite clear.

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@derrabus
Copy link
Member

I think, @stof and @xabbuh gave us very good reasons to close this feature request.

@derrabus derrabus closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants