From 1a8f49e51fa5793d723028504b104df5b09694f8 Mon Sep 17 00:00:00 2001 From: Liam Bishop Date: Sat, 28 Dec 2024 21:52:48 +0000 Subject: [PATCH] fix: check driver is Cake Driver before trying to access --- src/Http/SentryClient.php | 7 ++++++- src/Middleware/CakeSentryPerformanceMiddleware.php | 13 ++++++++----- src/Middleware/CakeSentryQueryMiddleware.php | 9 ++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Http/SentryClient.php b/src/Http/SentryClient.php index c8bfa78..2da1844 100644 --- a/src/Http/SentryClient.php +++ b/src/Http/SentryClient.php @@ -4,6 +4,7 @@ namespace CakeSentry\Http; use Cake\Core\Configure; +use Cake\Database\Driver; use Cake\Datasource\ConnectionManager; use Cake\Error\PhpError; use Cake\Event\Event; @@ -53,13 +54,17 @@ protected function getQueryLoggers(): void $includeSchemaReflection = (bool)Configure::read('CakeSentry.includeSchemaReflection'); foreach ($configs as $name) { + $logger = null; $connection = ConnectionManager::get($name); if ($connection->configName() === 'debug_kit') { continue; } /** @var \Cake\Database\Driver $driver */ $driver = $connection->getDriver(); - $logger = $driver->getLogger(); + + if ($driver instanceof Driver) { + $logger = $driver->getLogger(); + } if ($logger instanceof CakeSentryLog) { $logger->setIncludeSchema($includeSchemaReflection); diff --git a/src/Middleware/CakeSentryPerformanceMiddleware.php b/src/Middleware/CakeSentryPerformanceMiddleware.php index e2437d5..7dd188d 100644 --- a/src/Middleware/CakeSentryPerformanceMiddleware.php +++ b/src/Middleware/CakeSentryPerformanceMiddleware.php @@ -13,6 +13,7 @@ */ namespace CakeSentry\Middleware; +use Cake\Database\Driver; use Cake\Datasource\ConnectionManager; use Cake\Event\EventManager; use Cake\Http\Server; @@ -121,11 +122,13 @@ protected function addQueryData(): void $logger = null; /** @var \Cake\Database\Driver $driver */ $driver = $connection->getDriver(); - $driverConfig = $driver->config(); - if ($driverConfig['sentryLog'] ?? false) { - $logger = $driver->getLogger(); - if ($logger instanceof CakeSentryLog) { - $logger->setPerformanceMonitoring(true); + if ($driver instanceof Driver) { + $driverConfig = $driver->config(); + if ($driverConfig['sentryLog'] ?? false) { + $logger = $driver->getLogger(); + if ($logger instanceof CakeSentryLog) { + $logger->setPerformanceMonitoring(true); + } } } } diff --git a/src/Middleware/CakeSentryQueryMiddleware.php b/src/Middleware/CakeSentryQueryMiddleware.php index f62c36c..3a0a6ec 100644 --- a/src/Middleware/CakeSentryQueryMiddleware.php +++ b/src/Middleware/CakeSentryQueryMiddleware.php @@ -14,6 +14,7 @@ namespace CakeSentry\Middleware; use Cake\Core\Configure; +use Cake\Database\Driver; use Cake\Datasource\ConnectionManager; use CakeSentry\Database\Log\CakeSentryLog; use Psr\Http\Message\ResponseInterface; @@ -59,9 +60,11 @@ protected function enableQueryLogging(): void $logger = null; /** @var \Cake\Database\Driver $driver */ $driver = $connection->getDriver(); - $driverConfig = $driver->config(); - if ($driverConfig['sentryLog'] ?? false) { - $logger = $driver->getLogger(); + if ($driver instanceof Driver) { + $driverConfig = $driver->config(); + if ($driverConfig['sentryLog'] ?? false) { + $logger = $driver->getLogger(); + } } $logger = new CakeSentryLog($logger, $name, $includeSchemaReflection);