From 5d03f6e443e8d444bf9917ca44b1b553ecaa4896 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Sat, 14 Nov 2020 23:02:54 +0100 Subject: [PATCH] Use individual properties in Configuration This moves away from a global $_attributes associative array, towards individual properties. --- UPGRADE.md | 6 ++++ src/Configuration.php | 72 ++++++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 6a39841e50d..7fdb3893346 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -400,6 +400,12 @@ public function convert(Doctrine\DBAL\Driver\Exception $exception, ?Doctrine\DBA The constructor of `Doctrine\DBAL\Exception\DriverException` is now `@internal`. +## BC Break: `Configuration` + +- all `Configuration` methods are now typed +- `Configuration::setSchemaAssetsFilter()` now returns `void` +- `Configuration::$_attributes` has been removed; use individual properties in subclasses instead + # Upgrade to 2.12 ## Deprecated non-zero based positional parameter keys diff --git a/src/Configuration.php b/src/Configuration.php index 8f421f3501a..109289f5a30 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -15,61 +15,71 @@ class Configuration private $middlewares = []; /** - * The attributes that are contained in the configuration. - * Values are default values. + * The SQL logger in use. If null, SQL logging is disabled. * - * @var mixed[] + * @var SQLLogger|null */ - protected $_attributes = []; + protected $sqlLogger; /** - * Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled. + * The cache driver implementation that is used for query result caching. + * + * @var Cache|null + */ + protected $resultCacheImpl; + + /** + * The callable to use to filter schema assets. + * + * @var callable|null + */ + protected $schemaAssetsFilter; + + /** + * The default auto-commit mode for connections. * - * @return void + * @var bool */ - public function setSQLLogger(?SQLLogger $logger = null) + protected $autoCommit = true; + + /** + * Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled. + */ + public function setSQLLogger(?SQLLogger $logger = null): void { - $this->_attributes['sqlLogger'] = $logger; + $this->sqlLogger = $logger; } /** * Gets the SQL logger that is used. - * - * @return SQLLogger|null */ - public function getSQLLogger() + public function getSQLLogger(): ?SQLLogger { - return $this->_attributes['sqlLogger'] ?? null; + return $this->sqlLogger; } /** * Gets the cache driver implementation that is used for query result caching. - * - * @return Cache|null */ - public function getResultCacheImpl() + public function getResultCacheImpl(): ?Cache { - return $this->_attributes['resultCacheImpl'] ?? null; + return $this->resultCacheImpl; } /** * Sets the cache driver implementation that is used for query result caching. - * - * @return void */ - public function setResultCacheImpl(Cache $cacheImpl) + public function setResultCacheImpl(Cache $cacheImpl): void { - $this->_attributes['resultCacheImpl'] = $cacheImpl; + $this->resultCacheImpl = $cacheImpl; } /** * Sets the callable to use to filter schema assets. */ - public function setSchemaAssetsFilter(?callable $callable = null): ?callable + public function setSchemaAssetsFilter(?callable $callable = null): void { - $this->_attributes['filterSchemaAssetsExpression'] = null; - - return $this->_attributes['filterSchemaAssetsExpressionCallable'] = $callable; + $this->schemaAssetsFilter = $callable; } /** @@ -77,7 +87,7 @@ public function setSchemaAssetsFilter(?callable $callable = null): ?callable */ public function getSchemaAssetsFilter(): ?callable { - return $this->_attributes['filterSchemaAssetsExpressionCallable'] ?? null; + return $this->schemaAssetsFilter; } /** @@ -89,13 +99,11 @@ public function getSchemaAssetsFilter(): ?callable * * @see getAutoCommit * - * @param bool $autoCommit True to enable auto-commit mode; false to disable it. - * - * @return void + * @param bool $autoCommit True to enable auto-commit mode; false to disable it */ - public function setAutoCommit($autoCommit) + public function setAutoCommit(bool $autoCommit): void { - $this->_attributes['autoCommit'] = (bool) $autoCommit; + $this->autoCommit = $autoCommit; } /** @@ -105,9 +113,9 @@ public function setAutoCommit($autoCommit) * * @return bool True if auto-commit mode is enabled by default for connections, false otherwise. */ - public function getAutoCommit() + public function getAutoCommit(): bool { - return $this->_attributes['autoCommit'] ?? true; + return $this->autoCommit; } /**