Skip to content
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

Use individual properties in Configuration #4431

Merged
merged 1 commit into from Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE.md
Expand Up @@ -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
Expand Down
72 changes: 40 additions & 32 deletions src/Configuration.php
Expand Up @@ -15,69 +15,79 @@ 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;
}

/**
* Returns the callable to use to filter schema assets.
*/
public function getSchemaAssetsFilter(): ?callable
{
return $this->_attributes['filterSchemaAssetsExpressionCallable'] ?? null;
return $this->schemaAssetsFilter;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down