Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AbstractDriverMiddleware class instead of own implementation #810

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 5 additions & 55 deletions src/Tracing/Doctrine/DBAL/TracingDriverForV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

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 +17,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 +32,8 @@ 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();
}
}
Loading