public function TraceableEventDispatcher::dispatch in Devel 4.x
Same name and namespace in other branches
- 8.3 webprofiler/src/EventDispatcher/TraceableEventDispatcher.php \Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher::dispatch()
- 8 webprofiler/src/EventDispatcher/TraceableEventDispatcher.php \Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher::dispatch()
- 8.2 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\EventDispatcherCode
public function dispatch($event, $event_name = NULL) {
// Temporary hack for 9.0 and 9.1 compat. See https://gitlab.com/drupalspoons/devel/-/issues/344.
if (is_string($event)) {
$event_obj = $event_name ?? new Event();
$event_name = $event;
$event = $event_obj;
}
$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 &$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;
}