/** * Trigger an event. * * @param EventInterface|string $event The event object or name. * * @return EventInterface The event after being passed through all listeners. * * @since 1.0 */ public function triggerEvent($event) { if (!$event instanceof EventInterface) { if (isset($this->events[$event])) { $event = $this->events[$event]; } else { $event = new Event($event); } } if (isset($this->listeners[$event->getName()])) { foreach ($this->listeners[$event->getName()] as $listener) { if ($event->isStopped()) { return $event; } if ($listener instanceof Closure) { call_user_func($listener, $event); } else { call_user_func(array($listener, $event->getName()), $event); } } } return $event; }