eventName ?? get_class($this); } /** * @return bool * * @throws \BadMethodCallException */ public function isCancelled() : bool{ if(!($this instanceof Cancellable)){ throw new \BadMethodCallException(get_class($this) . " is not Cancellable"); } /** @var Event $this */ return $this->isCancelled; } /** * @param bool $value * * @throws \BadMethodCallException */ public function setCancelled(bool $value = true) : void{ if(!($this instanceof Cancellable)){ throw new \BadMethodCallException(get_class($this) . " is not Cancellable"); } /** @var Event $this */ $this->isCancelled = $value; } /** * Calls event handlers registered for this event. * * @throws \RuntimeException if event call recursion reaches the max depth limit * * @throws \ReflectionException */ public function call() : void{ if(self::$eventCallDepth >= self::MAX_EVENT_CALL_DEPTH){ //this exception will be caught by the parent event call if all else fails throw new \RuntimeException("Recursive event call detected (reached max depth of " . self::MAX_EVENT_CALL_DEPTH . " calls)"); } $handlerList = HandlerList::getHandlerListFor(get_class($this)); assert($handlerList !== null, "Called event should have a valid HandlerList"); ++self::$eventCallDepth; try{ foreach(EventPriority::ALL as $priority){ $currentList = $handlerList; while($currentList !== null){ foreach($currentList->getListenersByPriority($priority) as $registration){ $registration->callEvent($this); } $currentList = $currentList->getParent(); } } }finally{ --self::$eventCallDepth; } } }