public function ContainerAwareEventDispatcher::addSubscriberService

Adds a service as event subscriber

Parameters

string $serviceId The service ID of the subscriber service:

string $class The service's class name (which must implement EventSubscriberInterface):

File

drupal/core/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php, line 138

Class

ContainerAwareEventDispatcher
Lazily loads listeners and subscribers from the dependency injection container

Namespace

Symfony\Component\EventDispatcher

Code

public function addSubscriberService($serviceId, $class) {
  foreach ($class::getSubscribedEvents() as $eventName => $params) {
    if (is_string($params)) {
      $this->listenerIds[$eventName][] = array(
        $serviceId,
        $params,
        0,
      );
    }
    elseif (is_string($params[0])) {
      $this->listenerIds[$eventName][] = array(
        $serviceId,
        $params[0],
        isset($params[1]) ? $params[1] : 0,
      );
    }
    else {
      foreach ($params as $listener) {
        $this->listenerIds[$eventName][] = array(
          $serviceId,
          $listener[0],
          isset($listener[1]) ? $listener[1] : 0,
        );
      }
    }
  }
}