contributte / event-dispatcher

:boom: Best events support (symfony/event-dispatcher) to Nette Framework (@nette)
https://contributte.org/packages/contributte/event-dispatcher.html
MIT License
28 stars 8 forks source link

Feature suggestion: subscribe to all events with "*" #14

Closed gondik closed 5 years ago

gondik commented 5 years ago

Proposal

I've been thinking about potentially useful feature to subscribe to multiple events at once.

Something like this: public function getSubscribedEvents() { return [ '*' => 'processEvent' ]; }

Eventually, the events can be subscribed by namespace/regular: public function getSubscribedEvents() { return [ 'order.*' => 'processOrderEvent' ]; }

Can this be simply achieved through the Symfony events core?

Use case (example)

I am working on a large scale ERP system with many services and models and currently I am implementing "newsfeed" feature which will create records by various events of the services and models. So far I need to create subscriber line for every event separately. Feature like this can simplify this approach a lot.

mabar commented 5 years ago

Ideal, collision free naming of events look like this public const NAME = self::class;, so it would be just partial sollution.

Could you show an code example where multiple events could be processed with same method?

Imho this is usually solved by a command bus pattern and also, this package should be just integration of symfony events, which does not add so complicated features.

mabar commented 5 years ago

Not enough info, closing