You are here

public function TraceableEventDispatcher::dispatch in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/EventDispatcher/TraceableEventDispatcher.php \Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher::dispatch()
  2. 8.2 webprofiler/src/EventDispatcher/TraceableEventDispatcher.php \Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher::dispatch()
  3. 4.x webprofiler/src/EventDispatcher/TraceableEventDispatcher.php \Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher::dispatch()

Overrides ContainerAwareEventDispatcher::dispatch

File

webprofiler/src/EventDispatcher/TraceableEventDispatcher.php, line 51

Class

TraceableEventDispatcher
Class TraceableEventDispatcher

Namespace

Drupal\webprofiler\EventDispatcher

Code

public function dispatch($event_name, Event $event = NULL) {
  if ($event === NULL) {
    $event = new Event();
  }
  $this
    ->preDispatch($event_name, $event);
  $e = $this->stopwatch
    ->start($event_name, 'section');
  if (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]);
    }

    // Invoke 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],
          ];
        }
        $definition['callable']($event, $event_name, $this);
        $this
          ->addCalledListener($definition, $event_name, $priority);
        if ($event
          ->isPropagationStopped()) {
          return $event;
        }
      }
    }
  }
  if ($e
    ->isStarted()) {
    $e
      ->stop();
  }
  $this
    ->postDispatch($event_name, $event);
  return $event;
}