Skip to content

Commit

Permalink
Use AbstractDriverMiddleware class instead implementing the interfa…
Browse files Browse the repository at this point in the history
…ce (#810)

Co-authored-by: Stefano Arlandini <sarlandini@alice.it>
  • Loading branch information
oleg-andreyev and ste93cry committed Feb 19, 2024
1 parent fe4480a commit b42a9bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 57 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"symfony/security-http": "^4.4.20||^5.0.11||^6.0||^7.0"
},
"require-dev": {
"doctrine/dbal": "^2.13||^3.0",
"doctrine/dbal": "^2.13||^3.3",
"doctrine/doctrine-bundle": "^2.6",
"friendsofphp/php-cs-fixer": "^2.19||^3.40",
"masterminds/html5": "^2.8",
Expand Down
62 changes: 6 additions & 56 deletions src/Tracing/Doctrine/DBAL/TracingDriverForV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

namespace Sentry\SentryBundle\Tracing\Doctrine\DBAL;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;

/**
* This is a simple implementation of the {@see Driver} interface that decorates
Expand All @@ -20,18 +16,13 @@
*
* @phpstan-import-type Params from \Doctrine\DBAL\DriverManager as ConnectionParams
*/
final class TracingDriverForV3 implements Driver, VersionAwarePlatformDriver
final class TracingDriverForV3 extends AbstractDriverMiddleware
{
/**
* @var TracingDriverConnectionFactoryInterface The connection factory
*/
private $connectionFactory;

/**
* @var Driver|VersionAwarePlatformDriver The instance of the decorated driver
*/
private $decoratedDriver;

/**
* Constructor.
*
Expand All @@ -40,8 +31,9 @@ final class TracingDriverForV3 implements Driver, VersionAwarePlatformDriver
*/
public function __construct(TracingDriverConnectionFactoryInterface $connectionFactory, Driver $decoratedDriver)
{
parent::__construct($decoratedDriver);

$this->connectionFactory = $connectionFactory;
$this->decoratedDriver = $decoratedDriver;
}

/**
Expand All @@ -52,51 +44,9 @@ public function __construct(TracingDriverConnectionFactoryInterface $connectionF
public function connect(array $params): TracingDriverConnectionInterface
{
return $this->connectionFactory->create(
$this->decoratedDriver->connect($params),
$this->decoratedDriver->getDatabasePlatform(),
parent::connect($params),
$this->getDatabasePlatform(),
$params
);
}

/**
* {@inheritdoc}
*/
public function getDatabasePlatform(): AbstractPlatform
{
return $this->decoratedDriver->getDatabasePlatform();
}

/**
* {@inheritdoc}
*
* @phpstan-template T of AbstractPlatform
*
* @phpstan-param T $platform
*
* @phpstan-return AbstractSchemaManager<T>
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
{
return $this->decoratedDriver->getSchemaManager($conn, $platform);
}

/**
* {@inheritdoc}
*/
public function getExceptionConverter(): ExceptionConverter
{
return $this->decoratedDriver->getExceptionConverter();
}

/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version): AbstractPlatform
{
if ($this->decoratedDriver instanceof VersionAwarePlatformDriver) {
return $this->decoratedDriver->createDatabasePlatformForVersion($version);
}

return $this->getDatabasePlatform();
}
}

0 comments on commit b42a9bb

Please sign in to comment.