8.5.x EventDispatcher.php EventDispatcher::addSubscriber(EventSubscriberInterface $subscriber)
8.0.x EventDispatcher.php EventDispatcher::addSubscriber(EventSubscriberInterface $subscriber)
8.1.x EventDispatcher.php EventDispatcher::addSubscriber(EventSubscriberInterface $subscriber)
8.2.x EventDispatcher.php EventDispatcher::addSubscriber(EventSubscriberInterface $subscriber)
8.3.x EventDispatcher.php EventDispatcher::addSubscriber(EventSubscriberInterface $subscriber)
8.4.x EventDispatcher.php EventDispatcher::addSubscriber(EventSubscriberInterface $subscriber)
8.6.x EventDispatcher.php EventDispatcher::addSubscriber(EventSubscriberInterface $subscriber)

Adds an event subscriber.

The subscriber is asked for all the events he is interested in and added as a listener for these events.

Parameters

EventSubscriberInterface $subscriber The subscriber:

Overrides EventDispatcherInterface::addSubscriber

File

vendor/symfony/event-dispatcher/EventDispatcher.php, line 137

Class

EventDispatcher
The EventDispatcherInterface is the central point of Symfony's event listener system.

Namespace

Symfony\Component\EventDispatcher

Code

public function addSubscriber(EventSubscriberInterface $subscriber) {
  foreach ($subscriber
    ->getSubscribedEvents() as $eventName => $params) {
    if (is_string($params)) {
      $this
        ->addListener($eventName, array(
        $subscriber,
        $params,
      ));
    }
    elseif (is_string($params[0])) {
      $this
        ->addListener($eventName, array(
        $subscriber,
        $params[0],
      ), isset($params[1]) ? $params[1] : 0);
    }
    else {
      foreach ($params as $listener) {
        $this
          ->addListener($eventName, array(
          $subscriber,
          $listener[0],
        ), isset($listener[1]) ? $listener[1] : 0);
      }
    }
  }
}