You are here

public function ContainerAwareEventDispatcher::removeListener in Service Container 7.2

Same name and namespace in other branches
  1. 7 lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::removeListener()
1 call to ContainerAwareEventDispatcher::removeListener()
ContainerAwareEventDispatcher::removeSubscriber in lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php

File

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

Class

ContainerAwareEventDispatcher
A performance optimized container aware event dispatcher.

Namespace

Drupal\Component\EventDispatcher

Code

public function removeListener($event_name, $listener) {
  if (!isset($this->listeners[$event_name])) {
    return;
  }
  foreach ($this->listeners[$event_name] as $priority => $definitions) {
    foreach ($definitions as $key => $definition) {
      if (!isset($definition['callable'])) {
        if (!$this->container
          ->initialized($definition['service'][0])) {
          continue;
        }
        $definition['callable'] = [
          $this->container
            ->get($definition['service'][0]),
          $definition['service'][1],
        ];
      }
      if ($definition['callable'] === $listener) {
        unset($this->listeners[$event_name][$priority][$key]);
      }
    }
  }
}