You are here

public function ContainerAwareEventDispatcher::getListeners in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::getListeners()
1 call to ContainerAwareEventDispatcher::getListeners()
ContainerAwareEventDispatcher::hasListeners in lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php

File

lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php, line 130
Contains \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher.

Class

ContainerAwareEventDispatcher
A performance optimized container aware event dispatcher.

Namespace

Drupal\Component\EventDispatcher

Code

public function getListeners($event_name = NULL) {
  $result = [];
  if ($event_name === NULL) {

    // If event name was omitted, collect all listeners of all events.
    foreach (array_keys($this->listeners) as $event_name) {
      $listeners = $this
        ->getListeners($event_name);
      if (!empty($listeners)) {
        $result[$event_name] = $listeners;
      }
    }
  }
  elseif (isset($this->listeners[$event_name])) {

    // Sort listeners if necessary.
    if (isset($this->unsorted[$event_name])) {
      krsort($this->listeners[$event_name]);
      unset($this->unsorted[$event_name]);
    }

    // Collect listeners and resolve callables if necessary.
    foreach ($this->listeners[$event_name] as $priority => &$definitions) {
      foreach ($definitions as $key => &$definition) {
        if (!isset($definition['callable'])) {
          $definition['callable'] = [
            $this->container
              ->get($definition['service'][0]),
            $definition['service'][1],
          ];
        }
        $result[] = $definition['callable'];
      }
    }
  }
  return $result;
}