Do you like Symfony\Component\EventDispatcher\EventSubscriberInterface and it's getSubscribedEvents() method?
class AwesomeSubscriber implements Symfony\Component\EventDispatcher\EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
HappyEvent::class => 'happy',
CoolEvent::class => 'coll',
];
}
public function happy(HappyEvent $event): void {}
public function coll(CoolEvent $event): void {}
}
I hate it!
- Array with textual method name representation
- Event class-name written multiple times 😑
Yes, new Symfony has attribute #[AsEventListener], but what if you use another framework or older version of event-dispatcher or you don't like attributes?
There is simple solution 💥
See this trait and install
composer require zarganwar/symfony-event-dispatcher-utils
Enjoy! 🎉
SOCIAL SHARE CARD GENERATOR