diff --git a/src/Support/Events.php b/src/Support/Events.php index 66d8ae6..2caacde 100644 --- a/src/Support/Events.php +++ b/src/Support/Events.php @@ -54,7 +54,7 @@ class Events /** * @var LoggerInterface */ - protected static LoggerInterface $logger; + protected static ?LoggerInterface $logger = null; /** * Метод для регистрации обработчика события. @@ -114,7 +114,7 @@ public static function emit(string $event_name, mixed $data, bool $halt = false) $response = $listener($data, $event_name); } catch (Throwable $e) { $responses[] = $e; - if (!static::$logger && is_callable('\support\Log::error')) { + if (static::$logger === null && is_callable('\support\Log::error')) { static::$logger = Log::channel(); } static::$logger?->error($e); diff --git a/tests/engine_compatibility.php b/tests/engine_compatibility.php index 2dac625..e2b72f3 100644 --- a/tests/engine_compatibility.php +++ b/tests/engine_compatibility.php @@ -41,4 +41,13 @@ static function (array $data) use (&$received): void { throw new RuntimeException('The configured event listener did not receive its payload.'); } +$failureEvent = 'triangle.events.listener.failure'; +Events::on($failureEvent, static function (): never { + throw new RuntimeException('Expected listener failure.'); +}); +$failures = Events::emit($failureEvent, null); +if (count($failures) !== 1 || !($failures[0] instanceof RuntimeException)) { + throw new RuntimeException('Listener exceptions must be returned and logged without escaping emit().'); +} + echo "TRIANGLE_EVENTS_ENGINE_COMPATIBILITY=ok\n";