vendor/sentry/sentry-symfony/src/Tracing/Doctrine/DBAL/TracingDriverForV2.php line 48

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\DriverException;
  7. use Doctrine\DBAL\Driver\ExceptionConverterDriver;
  8. use Doctrine\DBAL\Exception\DriverException as DBALDriverException;
  9. use Doctrine\DBAL\Platforms\AbstractPlatform;
  10. use Doctrine\DBAL\Schema\AbstractSchemaManager;
  11. use Doctrine\DBAL\VersionAwarePlatformDriver;
  12. /**
  13.  * This is a simple implementation of the {@see Driver} interface that decorates
  14.  * an existing driver to support distributed tracing capabilities. This implementation
  15.  * is compatible only with DBAL version < 3.0.
  16.  *
  17.  * @internal
  18.  */
  19. final class TracingDriverForV2 implements DriverVersionAwarePlatformDriverExceptionConverterDriver
  20. {
  21.     /**
  22.      * @var TracingDriverConnectionFactoryInterface
  23.      */
  24.     private $connectionFactory;
  25.     /**
  26.      * @var Driver|VersionAwarePlatformDriver|ExceptionConverterDriver The instance of the decorated driver
  27.      */
  28.     private $decoratedDriver;
  29.     /**
  30.      * @param TracingDriverConnectionFactoryInterface $connectionFactory The connection factory
  31.      * @param Driver                                  $decoratedDriver   The instance of the driver to decorate
  32.      */
  33.     public function __construct(TracingDriverConnectionFactoryInterface $connectionFactoryDriver $decoratedDriver)
  34.     {
  35.         $this->decoratedDriver $decoratedDriver;
  36.         $this->connectionFactory $connectionFactory;
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public function connect(array $params$username null$password null, array $driverOptions = []): TracingDriverConnectionInterface
  42.     {
  43.         return $this->connectionFactory->create(
  44.             $this->decoratedDriver->connect($params$username$password$driverOptions),
  45.             $this->decoratedDriver->getDatabasePlatform(),
  46.             $params
  47.         );
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function getDatabasePlatform(): AbstractPlatform
  53.     {
  54.         return $this->decoratedDriver->getDatabasePlatform();
  55.     }
  56.     /**
  57.      * {@inheritdoc}
  58.      */
  59.     public function getSchemaManager(Connection $conn, ?AbstractPlatform $platform null): AbstractSchemaManager
  60.     {
  61.         return $this->decoratedDriver->getSchemaManager($conn$platform);
  62.     }
  63.     /**
  64.      * {@inheritdoc}
  65.      */
  66.     public function getName(): string
  67.     {
  68.         return $this->decoratedDriver->getName();
  69.     }
  70.     /**
  71.      * {@inheritdoc}
  72.      */
  73.     public function getDatabase(Connection $conn): ?string
  74.     {
  75.         return $this->decoratedDriver->getDatabase($conn);
  76.     }
  77.     /**
  78.      * {@inheritdoc}
  79.      */
  80.     public function createDatabasePlatformForVersion($version): AbstractPlatform
  81.     {
  82.         if ($this->decoratedDriver instanceof VersionAwarePlatformDriver) {
  83.             return $this->decoratedDriver->createDatabasePlatformForVersion($version);
  84.         }
  85.         return $this->getDatabasePlatform();
  86.     }
  87.     /**
  88.      * {@inheritdoc}
  89.      */
  90.     public function convertException($messageDriverException $exception): DBALDriverException
  91.     {
  92.         if ($this->decoratedDriver instanceof ExceptionConverterDriver) {
  93.             return $this->decoratedDriver->convertException($message$exception);
  94.         }
  95.         return new DBALDriverException($message$exception);
  96.     }
  97. }