Skip to content

Commit

Permalink
Merge pull request #4159 from morozov/wrapper-apis-are-not-driver-apis
Browse files Browse the repository at this point in the history
Do not implement driver-level interfaces by wrapper-level classes
  • Loading branch information
morozov committed Jul 10, 2020
2 parents 0f6b728 + 6d2b649 commit d415d04
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
4 changes: 4 additions & 0 deletions 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:
Expand Down
6 changes: 1 addition & 5 deletions docs/en/reference/architecture.rst
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/Connection.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1215,7 +1215,7 @@ protected function _getNestedTransactionSavePointName()
}

/**
* {@inheritDoc}
* @return bool
*/
public function beginTransaction()
{
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Connections/PrimaryReadReplicaConnection.php
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/Portability/Connection.php
Expand Up @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions src/Statement.php
Expand Up @@ -3,18 +3,16 @@
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;

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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d415d04

Please sign in to comment.