Dispatches an event to all registered listeners.
@api
string $eventName The name of the event to dispatch. The name of: the event is the name of the method that is invoked on listeners.
Event $event The event to pass to the event handlers/listeners.: If not supplied, an empty Event instance is created.
Overrides EventDispatcherInterface::dispatch
public function dispatch($eventName, Event $event = null) {
if (null === $event) {
$event = new Event();
}
$this->id = spl_object_hash($event);
$this
->preDispatch($eventName, $event);
$e = $this->stopwatch
->start($eventName, 'section');
$this->firstCalledEvent[$eventName] = $this->stopwatch
->start($eventName . '.loading', 'event_listener_loading');
if (!$this->dispatcher
->hasListeners($eventName)) {
$this->firstCalledEvent[$eventName]
->stop();
}
$this->dispatcher
->dispatch($eventName, $event);
// reset the id as another event might have been dispatched during the dispatching of this event
$this->id = spl_object_hash($event);
unset($this->firstCalledEvent[$eventName]);
$e
->stop();
$this
->postDispatch($eventName, $event);
return $event;
}