From 73a851b062696be01b4388f709c9248cfdfda14d Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Tue, 6 Jun 2023 15:20:34 +0200 Subject: [PATCH] Introduce TracingDriverForV3Point2 This driver does not implement the deprecated `VersionAwarePlatformDriver`. It's automatically picked when `doctrine/dbal` version `3.2.0` or higher is installed. Fixes #579 --- .github/workflows/tests.yaml | 12 +++ .../DBAL/TracingDriverForV3Point2.php | 90 +++++++++++++++++++ src/aliases.php | 9 +- 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/Tracing/Doctrine/DBAL/TracingDriverForV3Point2.php diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 16c124ff..14c0a4b6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,6 +30,8 @@ jobs: - 6.* dependencies: - highest + doctrine-dbal: + - highest exclude: - php: '7.2' symfony-version: 6.* @@ -47,6 +49,12 @@ jobs: - php: '8.0' symfony-version: 6.* dependencies: lowest + - php: '8.1' + symfony-version: 6.* + doctrine-dbal: '^2.13' + - php: '8.1' + symfony-version: 6.* + doctrine-dbal: '<3.2' steps: - name: Checkout @@ -68,6 +76,10 @@ jobs: run: composer require --dev phpunit/phpunit ^9.3.9 --no-update if: matrix.php == '8.0' && matrix.dependencies == 'lowest' + - name: Update Doctrine DBAL + run: composer require --dev doctrine/dbal "${{ matrix.doctrine-dbal }}" --no-update + if: matrix.doctrine-dbal != 'highest' + - name: Install dependencies uses: ramsey/composer-install@v1 with: diff --git a/src/Tracing/Doctrine/DBAL/TracingDriverForV3Point2.php b/src/Tracing/Doctrine/DBAL/TracingDriverForV3Point2.php new file mode 100644 index 00000000..d187dcdf --- /dev/null +++ b/src/Tracing/Doctrine/DBAL/TracingDriverForV3Point2.php @@ -0,0 +1,90 @@ += 3.2. + * + * @internal + * + * @phpstan-import-type Params from \Doctrine\DBAL\DriverManager as ConnectionParams + */ +final class TracingDriverForV3Point2 implements Driver +{ + /** + * @var TracingDriverConnectionFactoryInterface The connection factory + */ + private $connectionFactory; + + /** + * @var Driver|VersionAwarePlatformDriver The instance of the decorated driver + */ + private $decoratedDriver; + + /** + * Constructor. + * + * @param TracingDriverConnectionFactoryInterface $connectionFactory The connection factory + * @param Driver $decoratedDriver The instance of the driver to decorate + */ + public function __construct(TracingDriverConnectionFactoryInterface $connectionFactory, Driver $decoratedDriver) + { + $this->connectionFactory = $connectionFactory; + $this->decoratedDriver = $decoratedDriver; + } + + /** + * {@inheritdoc} + * + * @phpstan-param ConnectionParams $params + */ + public function connect(array $params): TracingDriverConnectionInterface + { + return $this->connectionFactory->create( + $this->decoratedDriver->connect($params), + $this->decoratedDriver->getDatabasePlatform(), + $params + ); + } + + /** + * {@inheritdoc} + */ + public function getDatabasePlatform(): AbstractPlatform + { + return $this->decoratedDriver->getDatabasePlatform(); + } + + /** + * {@inheritdoc} + * + * @phpstan-template T of AbstractPlatform + * + * @phpstan-param T $platform + * + * @phpstan-return AbstractSchemaManager + */ + public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager + { + return $this->decoratedDriver->getSchemaManager($conn, $platform); + } + + /** + * {@inheritdoc} + */ + public function getExceptionConverter(): ExceptionConverter + { + return $this->decoratedDriver->getExceptionConverter(); + } +} diff --git a/src/aliases.php b/src/aliases.php index 839a55c9..68d6145c 100644 --- a/src/aliases.php +++ b/src/aliases.php @@ -4,6 +4,7 @@ namespace Sentry\SentryBundle; +use Composer\InstalledVersions; use Doctrine\DBAL\Result; use Sentry\SentryBundle\Tracing\Cache\TraceableCacheAdapter; use Sentry\SentryBundle\Tracing\Cache\TraceableCacheAdapterForV2; @@ -15,6 +16,7 @@ use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverForV2; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverForV3; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingStatement; +use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverForV3Point2; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingStatementForV2; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingStatementForV3; use Sentry\SentryBundle\Tracing\HttpClient\TraceableHttpClient; @@ -53,7 +55,12 @@ class_alias(TraceableTagAwareCacheAdapterForV2::class, TraceableTagAwareCacheAda if (!class_exists(TracingStatement::class)) { if (class_exists(Result::class)) { class_alias(TracingStatementForV3::class, TracingStatement::class); - class_alias(TracingDriverForV3::class, TracingDriver::class); + + if (class_exists(InstalledVersions::class) && version_compare(InstalledVersions::getVersion('doctrine/dbal') ?? '0', '3.2', '>=')) { + class_alias(TracingDriverForV3Point2::class, 'Sentry\\SentryBundle\\Tracing\\Doctrine\\DBAL\\TracingDriver'); + } else { + class_alias(TracingDriverForV3::class, TracingDriver::class); + } } elseif (interface_exists(Result::class)) { class_alias(TracingStatementForV2::class, TracingStatement::class); class_alias(TracingDriverForV2::class, TracingDriver::class);