Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| LogErrorEventListener | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/event-dispatcher. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @copyright Copyright (c) 2025-2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | * @license https://opensource.org/licenses/MIT MIT License |
| 13 | * |
| 14 | * @see https://github.com/php-fast-forward/event-dispatcher |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\EventDispatcher\Listener; |
| 20 | |
| 21 | use FastForward\EventDispatcher\Event\ErrorEvent; |
| 22 | use Psr\Log\LoggerInterface; |
| 23 | |
| 24 | /** |
| 25 | * Log dispatcher error events through a PSR-3 logger. |
| 26 | * |
| 27 | * The logged context includes both the throwable and the emitted {@see ErrorEvent}. |
| 28 | */ |
| 29 | class LogErrorEventListener |
| 30 | { |
| 31 | /** |
| 32 | * Create a listener that records dispatcher failures. |
| 33 | * |
| 34 | * @param LoggerInterface $logger logger used to record error events |
| 35 | */ |
| 36 | public function __construct( |
| 37 | private LoggerInterface $logger |
| 38 | ) {} |
| 39 | |
| 40 | /** |
| 41 | * Log the throwable carried by the provided error event. |
| 42 | * |
| 43 | * @param ErrorEvent $event error event emitted by the dispatcher |
| 44 | */ |
| 45 | public function __invoke(ErrorEvent $event): void |
| 46 | { |
| 47 | $throwable = $event->getThrowable(); |
| 48 | |
| 49 | $this->logger->error('An error occurred during event dispatching', [ |
| 50 | 'exception' => $throwable, |
| 51 | 'event' => $event, |
| 52 | ]); |
| 53 | } |
| 54 | } |