-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide abstract middleware classes #5035
Merged
derrabus
merged 1 commit into
doctrine:3.3.x
from
derrabus:improvement/abstract-middlewares
Nov 27, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Driver\Middleware; | ||
|
||
use Doctrine\DBAL\Driver\Connection; | ||
use Doctrine\DBAL\Driver\Result; | ||
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; | ||
use Doctrine\DBAL\Driver\Statement; | ||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\Deprecations\Deprecation; | ||
use LogicException; | ||
|
||
abstract class AbstractConnectionMiddleware implements ServerInfoAwareConnection | ||
{ | ||
/** @var Connection */ | ||
private $wrappedConnection; | ||
|
||
public function __construct(Connection $wrappedConnection) | ||
{ | ||
$this->wrappedConnection = $wrappedConnection; | ||
} | ||
|
||
public function prepare(string $sql): Statement | ||
{ | ||
return $this->wrappedConnection->prepare($sql); | ||
} | ||
|
||
public function query(string $sql): Result | ||
{ | ||
return $this->wrappedConnection->query($sql); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function quote($value, $type = ParameterType::STRING) | ||
{ | ||
return $this->wrappedConnection->quote($value, $type); | ||
} | ||
|
||
public function exec(string $sql): int | ||
{ | ||
return $this->wrappedConnection->exec($sql); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function lastInsertId($name = null) | ||
{ | ||
if ($name !== null) { | ||
Deprecation::triggerIfCalledFromOutside( | ||
'doctrine/dbal', | ||
'https://github.com/doctrine/dbal/issues/4687', | ||
'The usage of Connection::lastInsertId() with a sequence name is deprecated.' | ||
); | ||
} | ||
|
||
return $this->wrappedConnection->lastInsertId($name); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function beginTransaction() | ||
{ | ||
return $this->wrappedConnection->beginTransaction(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function commit() | ||
{ | ||
return $this->wrappedConnection->commit(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function rollBack() | ||
{ | ||
return $this->wrappedConnection->rollBack(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getServerVersion() | ||
{ | ||
if (! $this->wrappedConnection instanceof ServerInfoAwareConnection) { | ||
throw new LogicException('The underlying connection is not a ServerInfoAwareConnection'); | ||
} | ||
|
||
return $this->wrappedConnection->getServerVersion(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Driver\Middleware; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Driver; | ||
use Doctrine\DBAL\Driver\API\ExceptionConverter; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\VersionAwarePlatformDriver; | ||
|
||
abstract class AbstractDriverMiddleware implements VersionAwarePlatformDriver | ||
{ | ||
/** @var Driver */ | ||
private $wrappedDriver; | ||
|
||
public function __construct(Driver $wrappedDriver) | ||
{ | ||
$this->wrappedDriver = $wrappedDriver; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function connect(array $params) | ||
{ | ||
return $this->wrappedDriver->connect($params); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDatabasePlatform() | ||
{ | ||
return $this->wrappedDriver->getDatabasePlatform(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSchemaManager(Connection $conn, AbstractPlatform $platform) | ||
{ | ||
return $this->wrappedDriver->getSchemaManager($conn, $platform); | ||
} | ||
|
||
public function getExceptionConverter(): ExceptionConverter | ||
{ | ||
return $this->wrappedDriver->getExceptionConverter(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createDatabasePlatformForVersion($version) | ||
{ | ||
if ($this->wrappedDriver instanceof VersionAwarePlatformDriver) { | ||
return $this->wrappedDriver->createDatabasePlatformForVersion($version); | ||
} | ||
|
||
return $this->wrappedDriver->getDatabasePlatform(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Driver\Middleware; | ||
|
||
use Doctrine\DBAL\Driver\Result; | ||
|
||
abstract class AbstractResultMiddleware implements Result | ||
{ | ||
/** @var Result */ | ||
private $wrappedResult; | ||
|
||
public function __construct(Result $result) | ||
{ | ||
$this->wrappedResult = $result; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function fetchNumeric() | ||
{ | ||
return $this->wrappedResult->fetchNumeric(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function fetchAssociative() | ||
{ | ||
return $this->wrappedResult->fetchAssociative(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function fetchOne() | ||
{ | ||
return $this->wrappedResult->fetchOne(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function fetchAllNumeric(): array | ||
{ | ||
return $this->wrappedResult->fetchAllNumeric(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function fetchAllAssociative(): array | ||
{ | ||
return $this->wrappedResult->fetchAllAssociative(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function fetchFirstColumn(): array | ||
{ | ||
return $this->wrappedResult->fetchFirstColumn(); | ||
} | ||
|
||
public function rowCount(): int | ||
{ | ||
return $this->wrappedResult->rowCount(); | ||
} | ||
|
||
public function columnCount(): int | ||
{ | ||
return $this->wrappedResult->columnCount(); | ||
} | ||
|
||
public function free(): void | ||
{ | ||
$this->wrappedResult->free(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Driver\Middleware; | ||
|
||
use Doctrine\DBAL\Driver\Result; | ||
use Doctrine\DBAL\Driver\Statement; | ||
use Doctrine\DBAL\ParameterType; | ||
|
||
abstract class AbstractStatementMiddleware implements Statement | ||
{ | ||
/** @var Statement */ | ||
private $wrappedStatement; | ||
|
||
public function __construct(Statement $wrappedStatement) | ||
{ | ||
$this->wrappedStatement = $wrappedStatement; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function bindValue($param, $value, $type = ParameterType::STRING) | ||
{ | ||
return $this->wrappedStatement->bindValue($param, $value, $type); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) | ||
{ | ||
return $this->wrappedStatement->bindParam($param, $variable, $type, $length); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute($params = null): Result | ||
{ | ||
return $this->wrappedStatement->execute($params); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this property be
protected
or getter to be added?Otherwise how are supposed the
public
/middleware methods to be overriden?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it shouldn't.
You'll likely need to override the constructor anyway, so you can create your own private property for the wrapped driver if you really need it. Delegating a call to the wrapped driver can be done my calling the parent method, for example:
dbal/src/Logging/Driver.php
Lines 29 to 37 in 2485d0a