vendor/sentry/sentry-symfony/src/Tracing/Doctrine/DBAL/TracingDriverForV3.php line 55

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