Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Support/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Events
/**
* @var LoggerInterface
*/
protected static LoggerInterface $logger;
protected static ?LoggerInterface $logger = null;

/**
* Метод для регистрации обработчика события.
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions tests/engine_compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";