|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sentry\SentryBundle\Tracing\Doctrine\DBAL; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Connection; |
| 8 | +use Doctrine\DBAL\Driver; |
| 9 | +use Doctrine\DBAL\Driver\API\ExceptionConverter; |
| 10 | +use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 11 | +use Doctrine\DBAL\Schema\AbstractSchemaManager; |
| 12 | +use Doctrine\DBAL\VersionAwarePlatformDriver; |
| 13 | + |
| 14 | +/** |
| 15 | + * This is a simple implementation of the {@see Driver} interface that decorates |
| 16 | + * an existing driver to support distributed tracing capabilities. This implementation |
| 17 | + * is compatible with all versions of Doctrine DBAL >= 3.2. |
| 18 | + * |
| 19 | + * @internal |
| 20 | + * |
| 21 | + * @phpstan-import-type Params from \Doctrine\DBAL\DriverManager as ConnectionParams |
| 22 | + */ |
| 23 | +final class TracingDriverForV3Point2 implements Driver |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @var TracingDriverConnectionFactoryInterface The connection factory |
| 27 | + */ |
| 28 | + private $connectionFactory; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var Driver|VersionAwarePlatformDriver The instance of the decorated driver |
| 32 | + */ |
| 33 | + private $decoratedDriver; |
| 34 | + |
| 35 | + /** |
| 36 | + * Constructor. |
| 37 | + * |
| 38 | + * @param TracingDriverConnectionFactoryInterface $connectionFactory The connection factory |
| 39 | + * @param Driver $decoratedDriver The instance of the driver to decorate |
| 40 | + */ |
| 41 | + public function __construct(TracingDriverConnectionFactoryInterface $connectionFactory, Driver $decoratedDriver) |
| 42 | + { |
| 43 | + $this->connectionFactory = $connectionFactory; |
| 44 | + $this->decoratedDriver = $decoratedDriver; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * {@inheritdoc} |
| 49 | + * |
| 50 | + * @phpstan-param ConnectionParams $params |
| 51 | + */ |
| 52 | + public function connect(array $params): TracingDriverConnectionInterface |
| 53 | + { |
| 54 | + return $this->connectionFactory->create( |
| 55 | + $this->decoratedDriver->connect($params), |
| 56 | + $this->decoratedDriver->getDatabasePlatform(), |
| 57 | + $params |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * {@inheritdoc} |
| 63 | + */ |
| 64 | + public function getDatabasePlatform(): AbstractPlatform |
| 65 | + { |
| 66 | + return $this->decoratedDriver->getDatabasePlatform(); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * {@inheritdoc} |
| 71 | + * |
| 72 | + * @phpstan-template T of AbstractPlatform |
| 73 | + * |
| 74 | + * @phpstan-param T $platform |
| 75 | + * |
| 76 | + * @phpstan-return AbstractSchemaManager<T> |
| 77 | + */ |
| 78 | + public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager |
| 79 | + { |
| 80 | + return $this->decoratedDriver->getSchemaManager($conn, $platform); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * {@inheritdoc} |
| 85 | + */ |
| 86 | + public function getExceptionConverter(): ExceptionConverter |
| 87 | + { |
| 88 | + return $this->decoratedDriver->getExceptionConverter(); |
| 89 | + } |
| 90 | +} |
0 commit comments