From 6d2b649edb9268091ed01f3dd8c44bd0591311f9 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 8 Jul 2020 20:22:40 -0700 Subject: [PATCH] Do not implement driver-level interfaces by wrapper-level classes --- UPGRADE.md | 4 ++++ docs/en/reference/architecture.rst | 6 +----- src/Connection.php | 20 +++++++++---------- .../PrimaryReadReplicaConnection.php | 2 +- src/Portability/Connection.php | 3 --- src/Statement.php | 8 +++----- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 10a2aefc265..94d350ef2a6 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 3.0 +## BC BREAK: Changes in the wrapper-level API ancestry + +The wrapper-level `Connection` and `Statement` classes no longer implement the corresponding driver-level interfaces. + ## BC BREAK: Removed DBALException factory methods The following factory methods of the DBALException class have been removed: diff --git a/docs/en/reference/architecture.rst b/docs/en/reference/architecture.rst index f45eb51854b..5f14c52507a 100644 --- a/docs/en/reference/architecture.rst +++ b/docs/en/reference/architecture.rst @@ -16,11 +16,7 @@ interfaces are implemented by concrete drivers. For all PDO based drivers, ``PDO`` and ``PDOStatement`` are the implementations of these interfaces. Thus, for PDO-based drivers, a ``Doctrine\DBAL\Connection`` wraps a ``PDO`` instance and a -``Doctrine\DBAL\Statement`` wraps a ``PDOStatement`` instance. Even -more, a ``Doctrine\DBAL\Connection`` *is a* -``Doctrine\DBAL\Driver\Connection`` and a -``Doctrine\DBAL\Statement`` *is a* -``Doctrine\DBAL\Driver\Statement``. +``Doctrine\DBAL\Statement`` wraps a ``PDOStatement`` instance. What does a ``Doctrine\DBAL\Connection`` or a ``Doctrine\DBAL\Statement`` add to the underlying driver diff --git a/src/Connection.php b/src/Connection.php index 8e9fb4d0dc3..a6d7349bdc3 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -41,11 +41,10 @@ use function sprintf; /** - * A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like - * events, transaction isolation levels, configuration, emulated transaction nesting, - * lazy connecting and more. + * A database abstraction-level connection that implements features like events, transaction isolation levels, + * configuration, emulated transaction nesting, lazy connecting and more. */ -class Connection implements DriverConnection +class Connection { /** * Represents an array of ints to be expanded by Doctrine SQL parsing. @@ -757,7 +756,10 @@ public function quoteIdentifier($str) } /** - * {@inheritDoc} + * @param mixed $input + * @param int|string $type + * + * @return mixed */ public function quote($input, $type = ParameterType::STRING) { @@ -905,11 +907,9 @@ public function iterateColumn(string $query, array $params = [], array $types = * * @param string $sql The SQL statement to prepare. * - * @return Statement - * * @throws DBALException */ - public function prepare(string $sql): DriverStatement + public function prepare(string $sql): Statement { return new Statement($sql, $this); } @@ -1215,7 +1215,7 @@ protected function _getNestedTransactionSavePointName() } /** - * {@inheritDoc} + * @return bool */ public function beginTransaction() { @@ -1250,7 +1250,7 @@ public function beginTransaction() } /** - * {@inheritDoc} + * @return bool * * @throws ConnectionException If the commit failed due to no active transaction or * because the transaction was marked for rollback only. diff --git a/src/Connections/PrimaryReadReplicaConnection.php b/src/Connections/PrimaryReadReplicaConnection.php index 63f657798f0..2bf961900bd 100644 --- a/src/Connections/PrimaryReadReplicaConnection.php +++ b/src/Connections/PrimaryReadReplicaConnection.php @@ -10,9 +10,9 @@ use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver\Exception as DriverException; use Doctrine\DBAL\Driver\Result; -use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Statement; use InvalidArgumentException; use function array_rand; diff --git a/src/Portability/Connection.php b/src/Portability/Connection.php index eb433568750..e0b53c7969c 100644 --- a/src/Portability/Connection.php +++ b/src/Portability/Connection.php @@ -30,9 +30,6 @@ public function __construct(ConnectionInterface $connection, Converter $converte $this->converter = $converter; } - /** - * @return Statement - */ public function prepare(string $sql): DriverStatement { return new Statement( diff --git a/src/Statement.php b/src/Statement.php index cb1d3b509f4..4be12c6cc40 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL; use Doctrine\DBAL\Driver\Exception; -use Doctrine\DBAL\Driver\Result as DriverResult; use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; @@ -11,10 +10,9 @@ use function is_string; /** - * A thin wrapper around a Doctrine\DBAL\Driver\Statement that adds support - * for logging, DBAL mapping types, etc. + * A database abstraction-level statement that implements support for logging, DBAL mapping types, etc. */ -class Statement implements DriverStatement +class Statement { /** * The SQL statement. @@ -148,7 +146,7 @@ public function bindParam($name, &$var, $type = ParameterType::STRING, $length = * * @throws DBALException */ - public function execute($params = null): DriverResult + public function execute($params = null): Result { if ($params !== null) { $this->params = $params;