createdAt = microtime(true); } protected static function addStopwatch($key) { if (defined("__IS_DEBUG__")) { if (count(self::$performanceStopwatch) > 0) { $prev = end(self::$performanceStopwatch); self::$performanceStopwatch[$key] = microtime(true) - self::$createdAt - $prev; } else { self::$performanceStopwatch[$key] = microtime(true) - self::$createdAt; } } } public static function addStopwatchWithCallStack($key) { if (defined("__IS_DEBUG__")) { if ($key === 0) $key = "start"; else if ($key === 1) $key = "end"; $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $cf = $backtrace[1]['function'] ?? 'global scope'; self::addStopwatch("{$cf} {$key}"); } } public static function addEventHandler($event, $callback, $priority = 10) { if (!isset(self::$eventHandlers[$event])) { self::$eventHandlers[$event] = []; } self::$eventHandlers[$event][] = new Event($callback, $priority); } public static function triggerEvent($event, ...$data) { if (isset(self::$eventHandlers[$event])) { foreach (self::$eventHandlers[$event] as $callback) { $callback->getAction($data); } } } }