Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| InternalListener | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onEvent | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of the sshilko/php-sql-mydb package. |
| 4 | * |
| 5 | * (c) Sergei Shilko <contact@sshilko.com> |
| 6 | * |
| 7 | * MIT License |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | * @license https://opensource.org/licenses/mit-license.php MIT |
| 12 | */ |
| 13 | |
| 14 | declare(strict_types = 1); |
| 15 | |
| 16 | namespace sql\MydbListener; |
| 17 | |
| 18 | use Psr\Log\LoggerInterface; |
| 19 | use sql\MydbEvent\InternalConnectionBegin; |
| 20 | use sql\MydbEvent\InternalConnectionEnd; |
| 21 | use sql\MydbEventMetadataInterface; |
| 22 | use sql\MydbListener; |
| 23 | use function in_array; |
| 24 | use function is_array; |
| 25 | use function is_null; |
| 26 | |
| 27 | class InternalListener extends MydbListener |
| 28 | { |
| 29 | |
| 30 | public function __construct(protected ?LoggerInterface $logger = null) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | protected function onEvent(MydbEventMetadataInterface $event): ?bool |
| 35 | { |
| 36 | if (in_array($event->getEventName(), [InternalConnectionBegin::class, InternalConnectionEnd::class], true)) { |
| 37 | if ($this->logger) { |
| 38 | $this->logger->debug( |
| 39 | 'Received event: ' . $event->getEventName() |
| 40 | ); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return is_array($event->getEventMetadata()) || is_null($event->getEventMetadata()); |
| 45 | } |
| 46 | } |