Introduce the driver middleware interface

parent 386309c0
......@@ -3,16 +3,19 @@
namespace Doctrine\DBAL;
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Driver\Middleware;
use Doctrine\DBAL\Logging\SQLLogger;
/**
* Configuration container for the Doctrine DBAL.
*
* @internal When adding a new configuration option just write a getter/setter
* pair and add the option to the _attributes array with a proper default value.
* @internal
*/
class Configuration
{
/** @var Middleware[] */
private $middlewares = [];
/**
* The attributes that are contained in the configuration.
* Values are default values.
......@@ -108,4 +111,24 @@ class Configuration
{
return $this->_attributes['autoCommit'] ?? true;
}
/**
* @param Middleware[] $middlewares
*
* @return $this
*/
public function setMiddlewares(array $middlewares): self
{
$this->middlewares = $middlewares;
return $this;
}
/**
* @return Middleware[]
*/
public function getMiddlewares(): array
{
return $this->middlewares;
}
}
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver;
interface Middleware
{
public function wrap(Driver $driver): Driver;
}
......@@ -146,6 +146,10 @@ final class DriverManager
$driver = new $className();
foreach ($config->getMiddlewares() as $middleware) {
$driver = $middleware->wrap($driver);
}
$wrapperClass = Connection::class;
if (isset($params['wrapperClass'])) {
if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment