Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::getListenerPriority()
  2. 9 core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::getListenerPriority()

File

core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php, line 172

Class

ContainerAwareEventDispatcher
A performance optimized container aware event dispatcher.

Namespace

Drupal\Component\EventDispatcher

Code

public function getListenerPriority($event_name, $listener) : ?int {
  if (!isset($this->listeners[$event_name])) {
    return NULL;
  }
  if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
    $listener[0] = $listener[0]();
  }

  // Resolve service definitions if the listener has not been found so far.
  foreach ($this->listeners[$event_name] as $priority => &$definitions) {
    foreach ($definitions as &$definition) {
      if (!isset($definition['callable'])) {

        // Once the callable is retrieved we keep it for subsequent method
        // invocations on this class.
        $definition['callable'] = [
          $this->container
            ->get($definition['service'][0]),
          $definition['service'][1],
        ];
      }
      if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure) {
        $definition['callable'][0] = $definition['callable'][0]();
      }
      if ($definition['callable'] === $listener) {
        return $priority;
      }
    }
  }
  return NULL;
}