vendor/doctrine/dbal/src/Driver/Middleware/AbstractConnectionMiddleware.php line 34

Open in your IDE?
  1. <?php
  2. namespace Doctrine\DBAL\Driver\Middleware;
  3. use Doctrine\DBAL\Driver\Connection;
  4. use Doctrine\DBAL\Driver\Result;
  5. use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
  6. use Doctrine\DBAL\Driver\Statement;
  7. use Doctrine\DBAL\ParameterType;
  8. use Doctrine\Deprecations\Deprecation;
  9. use LogicException;
  10. use function get_class;
  11. use function method_exists;
  12. use function sprintf;
  13. abstract class AbstractConnectionMiddleware implements ServerInfoAwareConnection
  14. {
  15.     /** @var Connection */
  16.     private $wrappedConnection;
  17.     public function __construct(Connection $wrappedConnection)
  18.     {
  19.         $this->wrappedConnection $wrappedConnection;
  20.     }
  21.     public function prepare(string $sql): Statement
  22.     {
  23.         return $this->wrappedConnection->prepare($sql);
  24.     }
  25.     public function query(string $sql): Result
  26.     {
  27.         return $this->wrappedConnection->query($sql);
  28.     }
  29.     /**
  30.      * {@inheritdoc}
  31.      */
  32.     public function quote($value$type ParameterType::STRING)
  33.     {
  34.         return $this->wrappedConnection->quote($value$type);
  35.     }
  36.     public function exec(string $sql): int
  37.     {
  38.         return $this->wrappedConnection->exec($sql);
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function lastInsertId($name null)
  44.     {
  45.         if ($name !== null) {
  46.             Deprecation::triggerIfCalledFromOutside(
  47.                 'doctrine/dbal',
  48.                 'https://github.com/doctrine/dbal/issues/4687',
  49.                 'The usage of Connection::lastInsertId() with a sequence name is deprecated.'
  50.             );
  51.         }
  52.         return $this->wrappedConnection->lastInsertId($name);
  53.     }
  54.     /**
  55.      * {@inheritdoc}
  56.      */
  57.     public function beginTransaction()
  58.     {
  59.         return $this->wrappedConnection->beginTransaction();
  60.     }
  61.     /**
  62.      * {@inheritdoc}
  63.      */
  64.     public function commit()
  65.     {
  66.         return $this->wrappedConnection->commit();
  67.     }
  68.     /**
  69.      * {@inheritdoc}
  70.      */
  71.     public function rollBack()
  72.     {
  73.         return $this->wrappedConnection->rollBack();
  74.     }
  75.     /**
  76.      * {@inheritdoc}
  77.      */
  78.     public function getServerVersion()
  79.     {
  80.         if (! $this->wrappedConnection instanceof ServerInfoAwareConnection) {
  81.             throw new LogicException('The underlying connection is not a ServerInfoAwareConnection');
  82.         }
  83.         return $this->wrappedConnection->getServerVersion();
  84.     }
  85.     /**
  86.      * @return resource|object
  87.      */
  88.     public function getNativeConnection()
  89.     {
  90.         if (! method_exists($this->wrappedConnection'getNativeConnection')) {
  91.             throw new LogicException(sprintf(
  92.                 'The driver connection %s does not support accessing the native connection.',
  93.                 get_class($this->wrappedConnection)
  94.             ));
  95.         }
  96.         return $this->wrappedConnection->getNativeConnection();
  97.     }
  98. }