diff --git a/app/Core/Events/DispatchesEvents.php b/app/Core/Events/DispatchesEvents.php index 0b8d3adf3..203dbbf48 100644 --- a/app/Core/Events/DispatchesEvents.php +++ b/app/Core/Events/DispatchesEvents.php @@ -10,6 +10,7 @@ */ trait DispatchesEvents { + private static string $event_context = ''; /** * dispatches an event with context @@ -41,7 +42,7 @@ public static function dispatch_event(string $hook, mixed $available_params = [] */ public static function dispatch_filter(string $hook, mixed $payload, mixed $available_params = [], string|int $function = null): mixed { - return EventDispatcher::dispatch_filter($hook, $payload, $available_params, DispatchesEvents::get_event_context($function)); + return EventDispatcher::dispatch_filter($hook, $payload, $available_params, static::get_event_context($function)); } /** @@ -52,16 +53,17 @@ public static function dispatch_filter(string $hook, mixed $payload, mixed $avai * @param $function * @return string */ - public static function get_event_context($function): string + protected static function get_event_context($function): string { - - $event_context = DispatchesEvents::set_class_context(); + if (empty(self::$event_context)) { + self::$event_context = static::set_class_context(); + } $function = !empty($function) && is_string($function) && !is_numeric($function) ? $function - : DispatchesEvents::get_function_context(is_numeric($function) ? (int) $function : null); + : static::get_function_context(is_numeric($function) ? (int) $function : null); - return $event_context . '.' . $function; + return self::$event_context . '.' . $function; } /** @@ -72,7 +74,7 @@ public static function get_event_context($function): string * * @return string */ - public static function set_class_context(): string + private static function set_class_context(): string { return str_replace('\\', '.', strtolower(get_called_class())); } @@ -87,7 +89,7 @@ public static function set_class_context(): string * @param ?int $functionInt * @return string */ - public static function get_function_context(?int $functionInt = null): string + private static function get_function_context(?int $functionInt = null): string { $tracePointer = is_int($functionInt) ? $functionInt : 3;