diff --git a/src/Portability/Connection.php b/src/Portability/Connection.php index 3886a58ce99..fba779325fe 100644 --- a/src/Portability/Connection.php +++ b/src/Portability/Connection.php @@ -2,9 +2,13 @@ namespace Doctrine\DBAL\Portability; +use Doctrine\Common\EventManager; use Doctrine\DBAL\Abstraction\Result as AbstractionResult; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\ColumnCase; +use Doctrine\DBAL\Configuration; +use Doctrine\DBAL\Connection as BaseConnection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\Result as DriverResult; use Doctrine\DBAL\Driver\Statement as DriverStatement; @@ -17,7 +21,7 @@ /** * Portability wrapper for a Connection. */ -class Connection extends \Doctrine\DBAL\Connection +class Connection extends BaseConnection { public const PORTABILITY_ALL = 255; public const PORTABILITY_NONE = 0; @@ -25,9 +29,35 @@ class Connection extends \Doctrine\DBAL\Connection public const PORTABILITY_EMPTY_TO_NULL = 4; public const PORTABILITY_FIX_CASE = 8; + /** @var int */ + private $portability = self::PORTABILITY_NONE; + + /** @var int */ + private $case = 0; + /** @var Converter */ private $converter; + /** {@inheritDoc} */ + public function __construct( + array $params, + Driver $driver, + ?Configuration $config = null, + ?EventManager $eventManager = null + ) { + if (isset($params['portability'])) { + $this->portability = $params['portability']; + } + + if (isset($params['fetch_case'])) { + $this->case = $params['fetch_case']; + } + + unset($params['portability'], $params['fetch_case']); + + parent::__construct($params, $driver, $config, $eventManager); + } + /** * {@inheritdoc} */ @@ -35,24 +65,19 @@ public function connect() { $ret = parent::connect(); if ($ret) { - $params = $this->getParams(); - $portability = self::PORTABILITY_NONE; - - if (isset($params['portability'])) { - $portability = $params['portability'] = (new OptimizeFlags())( - $this->getDatabasePlatform(), - $params['portability'] - ); - } + $portability = (new OptimizeFlags())( + $this->getDatabasePlatform(), + $this->portability + ); - $case = null; + $case = 0; - if (isset($params['fetch_case']) && ($portability & self::PORTABILITY_FIX_CASE) !== 0) { + if ($this->case !== 0 && ($portability & self::PORTABILITY_FIX_CASE) !== 0) { if ($this->_conn instanceof PDOConnection) { // make use of c-level support for case handling - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_CASE, $params['fetch_case']); + $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_CASE, $this->case); } else { - $case = $params['fetch_case'] === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER; + $case = $this->case === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER; } }