eventName ?? get_class($this); } /** * Calls event handlers registered for this event. * * @throws \RuntimeException if event call recursion reaches the max depth limit */ public function call() : void{ $this->callDepth(function(){ $handlers = HandlerListManager::global()->getHandlersFor(static::class); foreach($handlers as $registration){ $registration->callEvent($this); } }); } /** * @template T * @phpstan-param \Closure() : T $closure * @phpstan-return T */ final protected function callDepth(\Closure $closure) : mixed{ 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)"); } $timings = Timings::getEventTimings($this); $timings->startTiming(); ++self::$eventCallDepth; try{ return $closure(); }finally{ --self::$eventCallDepth; $timings->stopTiming(); } } /** * Returns whether the current class context has any registered global handlers. * This can be used in hot code paths to avoid unnecessary event object creation. * * Usage: SomeEventClass::hasHandlers() */ public static function hasHandlers() : bool{ return count(HandlerListManager::global()->getHandlersFor(static::class)) > 0; } }