22declare(strict_types=1);
31use
function get_class;
34 private const MAX_EVENT_CALL_DEPTH = 50;
36 private static int $eventCallDepth = 1;
38 protected ?
string $eventName =
null;
40 final public function getEventName() :
string{
41 return $this->eventName ?? get_class($this);
49 public function call() : void{
50 if(self::$eventCallDepth >= self::MAX_EVENT_CALL_DEPTH){
52 throw new \RuntimeException(
"Recursive event call detected (reached max depth of " . self::MAX_EVENT_CALL_DEPTH .
" calls)");
55 $timings = Timings::getEventTimings($this);
56 $timings->startTiming();
58 $handlers = HandlerListManager::global()->getHandlersFor(static::class);
60 ++self::$eventCallDepth;
62 foreach($handlers as $registration){
63 $registration->callEvent($this);
66 --self::$eventCallDepth;
67 $timings->stopTiming();