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

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