use Symfony\Component\EventDispatcher\EventDispatcherInterface; class MySubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ MyEvent::NAME => 'onMyEvent', ]; } public function onMyEvent(MyEvent $event): void { // Handle the event } } $dispatcher->addSubscriber(new MySubscriber());In this example, we define a new subscriber called MySubscriber which is responsible for handling an event called MyEvent. We then add this subscriber to the EventDispatcherInterface using the addSubscriber method. The package library that this code belongs to is Symfony\Component\EventDispatcher.