Automated coding style fixes using phpcbf

parent ba4c9a25
...@@ -17,13 +17,13 @@ ...@@ -17,13 +17,13 @@
* <http://www.doctrine-project.org>. * <http://www.doctrine-project.org>.
*/ */
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\DBAL\Tools\Console\ConsoleRunner; use Doctrine\DBAL\Tools\Console\ConsoleRunner;
use Symfony\Component\Console\Helper\HelperSet;
$files = array(__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'); $files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
$loader = null; $loader = null;
$cwd = getcwd(); $cwd = getcwd();
$directories = array($cwd, $cwd . DIRECTORY_SEPARATOR . 'config'); $directories = [$cwd, $cwd . DIRECTORY_SEPARATOR . 'config'];
$configFile = null; $configFile = null;
foreach ($files as $file) { foreach ($files as $file) {
...@@ -34,7 +34,7 @@ foreach ($files as $file) { ...@@ -34,7 +34,7 @@ foreach ($files as $file) {
} }
} }
if ( ! $loader) { if (! $loader) {
throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?'); throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?');
} }
...@@ -46,22 +46,22 @@ foreach ($directories as $directory) { ...@@ -46,22 +46,22 @@ foreach ($directories as $directory) {
} }
} }
if ( ! file_exists($configFile)) { if (! file_exists($configFile)) {
ConsoleRunner::printCliConfigTemplate(); ConsoleRunner::printCliConfigTemplate();
exit(1); exit(1);
} }
if ( ! is_readable($configFile)) { if (! is_readable($configFile)) {
echo 'Configuration file [' . $configFile . '] does not have read permission.' . PHP_EOL; echo 'Configuration file [' . $configFile . '] does not have read permission.' . PHP_EOL;
exit(1); exit(1);
} }
$commands = array(); $commands = [];
$helperSet = require $configFile; $helperSet = require $configFile;
if ( ! $helperSet instanceof HelperSet) { if (! $helperSet instanceof HelperSet) {
foreach ($GLOBALS as $helperSetCandidate) { foreach ($GLOBALS as $helperSetCandidate) {
if ($helperSetCandidate instanceof HelperSet) { if ($helperSetCandidate instanceof HelperSet) {
$helperSet = $helperSetCandidate; $helperSet = $helperSetCandidate;
......
...@@ -2,33 +2,29 @@ ...@@ -2,33 +2,29 @@
namespace Doctrine\DBAL\Cache; namespace Doctrine\DBAL\Cache;
use ArrayIterator;
use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use function array_merge; use function array_merge;
use function array_values; use function array_values;
use function count; use function count;
use function reset; use function reset;
class ArrayStatement implements \IteratorAggregate, ResultStatement class ArrayStatement implements IteratorAggregate, ResultStatement
{ {
/** /** @var array */
* @var array
*/
private $data; private $data;
/** /** @var int */
* @var int
*/
private $columnCount = 0; private $columnCount = 0;
/** /** @var int */
* @var int
*/
private $num = 0; private $num = 0;
/** /** @var int */
* @var int
*/
private $defaultFetchMode = FetchMode::MIXED; private $defaultFetchMode = FetchMode::MIXED;
/** /**
...@@ -37,9 +33,11 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement ...@@ -37,9 +33,11 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
public function __construct(array $data) public function __construct(array $data)
{ {
$this->data = $data; $this->data = $data;
if (count($data)) { if (! count($data)) {
$this->columnCount = count($data[0]); return;
} }
$this->columnCount = count($data[0]);
} }
/** /**
...@@ -47,7 +45,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement ...@@ -47,7 +45,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
*/ */
public function closeCursor() public function closeCursor()
{ {
unset ($this->data); unset($this->data);
} }
/** /**
...@@ -64,7 +62,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement ...@@ -64,7 +62,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{ {
if ($arg2 !== null || $arg3 !== null) { if ($arg2 !== null || $arg3 !== null) {
throw new \InvalidArgumentException("Caching layer does not support 2nd/3rd argument to setFetchMode()"); throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
} }
$this->defaultFetchMode = $fetchMode; $this->defaultFetchMode = $fetchMode;
...@@ -79,13 +77,13 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement ...@@ -79,13 +77,13 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
{ {
$data = $this->fetchAll(); $data = $this->fetchAll();
return new \ArrayIterator($data); return new ArrayIterator($data);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{ {
if (! isset($this->data[$this->num])) { if (! isset($this->data[$this->num])) {
return false; return false;
...@@ -110,7 +108,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement ...@@ -110,7 +108,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
return reset($row); return reset($row);
} }
throw new \InvalidArgumentException('Invalid fetch-style given for fetching result.'); throw new InvalidArgumentException('Invalid fetch-style given for fetching result.');
} }
/** /**
......
...@@ -2,18 +2,16 @@ ...@@ -2,18 +2,16 @@
namespace Doctrine\DBAL\Cache; namespace Doctrine\DBAL\Cache;
/** use Doctrine\DBAL\DBALException;
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @since 2.2 class CacheException extends DBALException
*/
class CacheException extends \Doctrine\DBAL\DBALException
{ {
/** /**
* @return \Doctrine\DBAL\Cache\CacheException * @return \Doctrine\DBAL\Cache\CacheException
*/ */
public static function noCacheKey() public static function noCacheKey()
{ {
return new self("No cache key was set."); return new self('No cache key was set.');
} }
/** /**
...@@ -21,6 +19,6 @@ class CacheException extends \Doctrine\DBAL\DBALException ...@@ -21,6 +19,6 @@ class CacheException extends \Doctrine\DBAL\DBALException
*/ */
public static function noResultDriverConfigured() public static function noResultDriverConfigured()
{ {
return new self("Trying to cache a query but no result driver is configured."); return new self('Trying to cache a query but no result driver is configured.');
} }
} }
...@@ -14,19 +14,13 @@ use function sha1; ...@@ -14,19 +14,13 @@ use function sha1;
*/ */
class QueryCacheProfile class QueryCacheProfile
{ {
/** /** @var Cache|null */
* @var Cache|null
*/
private $resultCacheDriver; private $resultCacheDriver;
/** /** @var int */
* @var int
*/
private $lifetime = 0; private $lifetime = 0;
/** /** @var string|null */
* @var string|null
*/
private $cacheKey; private $cacheKey;
/** /**
...@@ -98,7 +92,6 @@ class QueryCacheProfile ...@@ -98,7 +92,6 @@ class QueryCacheProfile
} }
/** /**
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile * @return \Doctrine\DBAL\Cache\QueryCacheProfile
*/ */
public function setResultCacheDriver(Cache $cache) public function setResultCacheDriver(Cache $cache)
......
...@@ -2,10 +2,14 @@ ...@@ -2,10 +2,14 @@
namespace Doctrine\DBAL\Cache; namespace Doctrine\DBAL\Cache;
use Doctrine\DBAL\Driver\Statement; use ArrayIterator;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use function array_merge; use function array_merge;
use function array_values; use function array_values;
use function reset; use function reset;
...@@ -23,32 +27,21 @@ use function reset; ...@@ -23,32 +27,21 @@ use function reset;
* Also you have to realize that the cache will load the whole result into memory at once to ensure 2. * Also you have to realize that the cache will load the whole result into memory at once to ensure 2.
* This means that the memory usage for cached results might increase by using this feature. * This means that the memory usage for cached results might increase by using this feature.
*/ */
class ResultCacheStatement implements \IteratorAggregate, ResultStatement class ResultCacheStatement implements IteratorAggregate, ResultStatement
{ {
/** /** @var Cache */
* @var \Doctrine\Common\Cache\Cache
*/
private $resultCache; private $resultCache;
/** /** @var string */
*
* @var string
*/
private $cacheKey; private $cacheKey;
/** /** @var string */
* @var string
*/
private $realKey; private $realKey;
/** /** @var int */
* @var int
*/
private $lifetime; private $lifetime;
/** /** @var Statement */
* @var \Doctrine\DBAL\Driver\Statement
*/
private $statement; private $statement;
/** /**
...@@ -58,30 +51,24 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -58,30 +51,24 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
*/ */
private $emptied = false; private $emptied = false;
/** /** @var array */
* @var array
*/
private $data; private $data;
/** /** @var int */
* @var int
*/
private $defaultFetchMode = FetchMode::MIXED; private $defaultFetchMode = FetchMode::MIXED;
/** /**
* @param \Doctrine\DBAL\Driver\Statement $stmt * @param string $cacheKey
* @param \Doctrine\Common\Cache\Cache $resultCache * @param string $realKey
* @param string $cacheKey * @param int $lifetime
* @param string $realKey
* @param int $lifetime
*/ */
public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime) public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime)
{ {
$this->statement = $stmt; $this->statement = $stmt;
$this->resultCache = $resultCache; $this->resultCache = $resultCache;
$this->cacheKey = $cacheKey; $this->cacheKey = $cacheKey;
$this->realKey = $realKey; $this->realKey = $realKey;
$this->lifetime = $lifetime; $this->lifetime = $lifetime;
} }
/** /**
...@@ -90,16 +77,18 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -90,16 +77,18 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
public function closeCursor() public function closeCursor()
{ {
$this->statement->closeCursor(); $this->statement->closeCursor();
if ($this->emptied && $this->data !== null) { if (! $this->emptied || $this->data === null) {
$data = $this->resultCache->fetch($this->cacheKey); return;
if ( ! $data) { }
$data = [];
}
$data[$this->realKey] = $this->data;
$this->resultCache->save($this->cacheKey, $data, $this->lifetime); $data = $this->resultCache->fetch($this->cacheKey);
unset($this->data); if (! $data) {
$data = [];
} }
$data[$this->realKey] = $this->data;
$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
unset($this->data);
} }
/** /**
...@@ -127,13 +116,13 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -127,13 +116,13 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
{ {
$data = $this->fetchAll(); $data = $this->fetchAll();
return new \ArrayIterator($data); return new ArrayIterator($data);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{ {
if ($this->data === null) { if ($this->data === null) {
$this->data = []; $this->data = [];
...@@ -162,7 +151,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -162,7 +151,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
return reset($row); return reset($row);
} }
throw new \InvalidArgumentException('Invalid fetch-style given for caching result.'); throw new InvalidArgumentException('Invalid fetch-style given for caching result.');
} }
$this->emptied = true; $this->emptied = true;
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Doctrine\DBAL; namespace Doctrine\DBAL;
use PDO;
/** /**
* Contains portable column case conversions. * Contains portable column case conversions.
*/ */
...@@ -12,14 +14,14 @@ final class ColumnCase ...@@ -12,14 +14,14 @@ final class ColumnCase
* *
* @see \PDO::CASE_UPPER * @see \PDO::CASE_UPPER
*/ */
public const UPPER = \PDO::CASE_UPPER; public const UPPER = PDO::CASE_UPPER;
/** /**
* Convert column names to lower case. * Convert column names to lower case.
* *
* @see \PDO::CASE_LOWER * @see \PDO::CASE_LOWER
*/ */
public const LOWER = \PDO::CASE_LOWER; public const LOWER = PDO::CASE_LOWER;
/** /**
* This class cannot be instantiated. * This class cannot be instantiated.
......
...@@ -2,16 +2,12 @@ ...@@ -2,16 +2,12 @@
namespace Doctrine\DBAL; namespace Doctrine\DBAL;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Logging\SQLLogger;
/** /**
* Configuration container for the Doctrine DBAL. * Configuration container for the Doctrine DBAL.
* *
* @since 2.0
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @internal When adding a new configuration option just write a getter/setter * @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. * pair and add the option to the _attributes array with a proper default value.
*/ */
...@@ -28,11 +24,9 @@ class Configuration ...@@ -28,11 +24,9 @@ class Configuration
/** /**
* Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled. * Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled.
* *
* @param \Doctrine\DBAL\Logging\SQLLogger|null $logger
*
* @return void * @return void
*/ */
public function setSQLLogger(SQLLogger $logger = null) public function setSQLLogger(?SQLLogger $logger = null)
{ {
$this->_attributes['sqlLogger'] = $logger; $this->_attributes['sqlLogger'] = $logger;
} }
...@@ -40,7 +34,7 @@ class Configuration ...@@ -40,7 +34,7 @@ class Configuration
/** /**
* Gets the SQL logger that is used. * Gets the SQL logger that is used.
* *
* @return \Doctrine\DBAL\Logging\SQLLogger|null * @return SQLLogger|null
*/ */
public function getSQLLogger() public function getSQLLogger()
{ {
...@@ -50,7 +44,7 @@ class Configuration ...@@ -50,7 +44,7 @@ class Configuration
/** /**
* Gets the cache driver implementation that is used for query result caching. * Gets the cache driver implementation that is used for query result caching.
* *
* @return \Doctrine\Common\Cache\Cache|null * @return Cache|null
*/ */
public function getResultCacheImpl() public function getResultCacheImpl()
{ {
...@@ -60,8 +54,6 @@ class Configuration ...@@ -60,8 +54,6 @@ class Configuration
/** /**
* Sets the cache driver implementation that is used for query result caching. * Sets the cache driver implementation that is used for query result caching.
* *
* @param \Doctrine\Common\Cache\Cache $cacheImpl
*
* @return void * @return void
*/ */
public function setResultCacheImpl(Cache $cacheImpl) public function setResultCacheImpl(Cache $cacheImpl)
...@@ -102,21 +94,21 @@ class Configuration ...@@ -102,21 +94,21 @@ class Configuration
* transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either * transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
* the method commit or the method rollback. By default, new connections are in auto-commit mode. * the method commit or the method rollback. By default, new connections are in auto-commit mode.
* *
* @param bool $autoCommit True to enable auto-commit mode; false to disable it.
*
* @see getAutoCommit * @see getAutoCommit
*
* @param bool $autoCommit True to enable auto-commit mode; false to disable it.
*/ */
public function setAutoCommit($autoCommit) public function setAutoCommit($autoCommit)
{ {
$this->_attributes['autoCommit'] = (boolean) $autoCommit; $this->_attributes['autoCommit'] = (bool) $autoCommit;
} }
/** /**
* Returns the default auto-commit mode for connections. * Returns the default auto-commit mode for connections.
* *
* @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
*
* @see setAutoCommit * @see setAutoCommit
*
* @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
*/ */
public function getAutoCommit() public function getAutoCommit()
{ {
......
This diff is collapsed.
...@@ -4,8 +4,6 @@ namespace Doctrine\DBAL; ...@@ -4,8 +4,6 @@ namespace Doctrine\DBAL;
/** /**
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0
* @author Jonathan H. Wage <jonwage@gmail.com
*/ */
class ConnectionException extends DBALException class ConnectionException extends DBALException
{ {
...@@ -14,7 +12,7 @@ class ConnectionException extends DBALException ...@@ -14,7 +12,7 @@ class ConnectionException extends DBALException
*/ */
public static function commitFailedRollbackOnly() public static function commitFailedRollbackOnly()
{ {
return new self("Transaction commit failed because the transaction has been marked for rollback only."); return new self('Transaction commit failed because the transaction has been marked for rollback only.');
} }
/** /**
...@@ -22,7 +20,7 @@ class ConnectionException extends DBALException ...@@ -22,7 +20,7 @@ class ConnectionException extends DBALException
*/ */
public static function noActiveTransaction() public static function noActiveTransaction()
{ {
return new self("There is no active transaction."); return new self('There is no active transaction.');
} }
/** /**
...@@ -30,7 +28,7 @@ class ConnectionException extends DBALException ...@@ -30,7 +28,7 @@ class ConnectionException extends DBALException
*/ */
public static function savepointsNotSupported() public static function savepointsNotSupported()
{ {
return new self("Savepoints are not supported by this driver."); return new self('Savepoints are not supported by this driver.');
} }
/** /**
...@@ -38,6 +36,6 @@ class ConnectionException extends DBALException ...@@ -38,6 +36,6 @@ class ConnectionException extends DBALException
*/ */
public static function mayNotAlterNestedTransactionWithSavepointsInTransaction() public static function mayNotAlterNestedTransactionWithSavepointsInTransaction()
{ {
return new self("May not alter the nested transaction with savepoints behavior while a transaction is open."); return new self('May not alter the nested transaction with savepoints behavior while a transaction is open.');
} }
} }
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
namespace Doctrine\DBAL\Connections; namespace Doctrine\DBAL\Connections;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use InvalidArgumentException;
use function array_rand; use function array_rand;
use function count; use function count;
use function func_get_args; use function func_get_args;
...@@ -63,9 +64,6 @@ use function func_get_args; ...@@ -63,9 +64,6 @@ use function func_get_args;
* )); * ));
* *
* You can also pass 'driverOptions' and any other documented option to each of this drivers to pass additional information. * You can also pass 'driverOptions' and any other documented option to each of this drivers to pass additional information.
*
* @author Lars Strojny <lstrojny@php.net>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class MasterSlaveConnection extends Connection class MasterSlaveConnection extends Connection
{ {
...@@ -87,20 +85,17 @@ class MasterSlaveConnection extends Connection ...@@ -87,20 +85,17 @@ class MasterSlaveConnection extends Connection
/** /**
* Creates Master Slave Connection. * Creates Master Slave Connection.
* *
* @param array $params * @param array $params
* @param \Doctrine\DBAL\Driver $driver
* @param \Doctrine\DBAL\Configuration|null $config
* @param \Doctrine\Common\EventManager|null $eventManager
* *
* @throws \InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null) public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null)
{ {
if (! isset($params['slaves'], $params['master'])) { if (! isset($params['slaves'], $params['master'])) {
throw new \InvalidArgumentException('master or slaves configuration missing'); throw new InvalidArgumentException('master or slaves configuration missing');
} }
if (count($params['slaves']) == 0) { if (count($params['slaves']) === 0) {
throw new \InvalidArgumentException('You have to configure at least one slaves.'); throw new InvalidArgumentException('You have to configure at least one slaves.');
} }
$params['master']['driver'] = $params['driver']; $params['master']['driver'] = $params['driver'];
...@@ -132,13 +127,13 @@ class MasterSlaveConnection extends Connection ...@@ -132,13 +127,13 @@ class MasterSlaveConnection extends Connection
$connectionName = $connectionName ?: 'slave'; $connectionName = $connectionName ?: 'slave';
if ($connectionName !== 'slave' && $connectionName !== 'master') { if ($connectionName !== 'slave' && $connectionName !== 'master') {
throw new \InvalidArgumentException("Invalid option to connect(), only master or slave allowed."); throw new InvalidArgumentException('Invalid option to connect(), only master or slave allowed.');
} }
// If we have a connection open, and this is not an explicit connection // If we have a connection open, and this is not an explicit connection
// change request, then abort right here, because we are already done. // change request, then abort right here, because we are already done.
// This prevents writes to the slave in case of "keepSlave" option enabled. // This prevents writes to the slave in case of "keepSlave" option enabled.
if (isset($this->_conn) && $this->_conn && !$requestedConnectionChange) { if (isset($this->_conn) && $this->_conn && ! $requestedConnectionChange) {
return false; return false;
} }
...@@ -163,7 +158,7 @@ class MasterSlaveConnection extends Connection ...@@ -163,7 +158,7 @@ class MasterSlaveConnection extends Connection
$this->connections['master'] = $this->_conn = $this->connectTo($connectionName); $this->connections['master'] = $this->_conn = $this->connectTo($connectionName);
// Set slave connection to master to avoid invalid reads // Set slave connection to master to avoid invalid reads
if ( ! $this->keepSlave) { if (! $this->keepSlave) {
$this->connections['slave'] = $this->connections['master']; $this->connections['slave'] = $this->connections['master'];
} }
} else { } else {
...@@ -193,7 +188,7 @@ class MasterSlaveConnection extends Connection ...@@ -193,7 +188,7 @@ class MasterSlaveConnection extends Connection
$connectionParams = $this->chooseConnectionConfiguration($connectionName, $params); $connectionParams = $this->chooseConnectionConfiguration($connectionName, $params);
$user = $connectionParams['user'] ?? null; $user = $connectionParams['user'] ?? null;
$password = $connectionParams['password'] ?? null; $password = $connectionParams['password'] ?? null;
return $this->_driver->connect($connectionParams, $user, $password, $driverOptions); return $this->_driver->connect($connectionParams, $user, $password, $driverOptions);
...@@ -213,7 +208,7 @@ class MasterSlaveConnection extends Connection ...@@ -213,7 +208,7 @@ class MasterSlaveConnection extends Connection
$config = $params['slaves'][array_rand($params['slaves'])]; $config = $params['slaves'][array_rand($params['slaves'])];
if ( ! isset($config['charset']) && isset($params['master']['charset'])) { if (! isset($config['charset']) && isset($params['master']['charset'])) {
$config['charset'] = $params['master']['charset']; $config['charset'] = $params['master']['charset'];
} }
...@@ -279,7 +274,7 @@ class MasterSlaveConnection extends Connection ...@@ -279,7 +274,7 @@ class MasterSlaveConnection extends Connection
parent::close(); parent::close();
$this->_conn = null; $this->_conn = null;
$this->connections = ['master' => null, 'slave' => null]; $this->connections = ['master' => null, 'slave' => null];
} }
......
This diff is collapsed.
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
namespace Doctrine\DBAL; namespace Doctrine\DBAL;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
/** /**
* Driver interface. * Driver interface.
* Interface that all DBAL drivers must implement. * Interface that all DBAL drivers must implement.
*
* @since 2.0
*/ */
interface Driver interface Driver
{ {
...@@ -26,7 +27,7 @@ interface Driver ...@@ -26,7 +27,7 @@ interface Driver
* Gets the DatabasePlatform instance that provides all the metadata about * Gets the DatabasePlatform instance that provides all the metadata about
* the platform this driver connects to. * the platform this driver connects to.
* *
* @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform. * @return AbstractPlatform The database platform.
*/ */
public function getDatabasePlatform(); public function getDatabasePlatform();
...@@ -34,9 +35,7 @@ interface Driver ...@@ -34,9 +35,7 @@ interface Driver
* Gets the SchemaManager that can be used to inspect and change the underlying * Gets the SchemaManager that can be used to inspect and change the underlying
* database schema of the platform this driver connects to. * database schema of the platform this driver connects to.
* *
* @param \Doctrine\DBAL\Connection $conn * @return AbstractSchemaManager
*
* @return \Doctrine\DBAL\Schema\AbstractSchemaManager
*/ */
public function getSchemaManager(Connection $conn); public function getSchemaManager(Connection $conn);
...@@ -50,8 +49,6 @@ interface Driver ...@@ -50,8 +49,6 @@ interface Driver
/** /**
* Gets the name of the database connected to for this driver. * Gets the name of the database connected to for this driver.
* *
* @param \Doctrine\DBAL\Connection $conn
*
* @return string The name of the database. * @return string The name of the database.
*/ */
public function getDatabase(Connection $conn); public function getDatabase(Connection $conn);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager; use Doctrine\DBAL\Schema\DB2SchemaManager;
...@@ -9,16 +10,14 @@ use Doctrine\DBAL\Schema\DB2SchemaManager; ...@@ -9,16 +10,14 @@ use Doctrine\DBAL\Schema\DB2SchemaManager;
/** /**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for IBM DB2 based drivers. * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for IBM DB2 based drivers.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
abstract class AbstractDB2Driver implements Driver abstract class AbstractDB2Driver implements Driver
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();
...@@ -36,7 +35,7 @@ abstract class AbstractDB2Driver implements Driver ...@@ -36,7 +35,7 @@ abstract class AbstractDB2Driver implements Driver
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) public function getSchemaManager(Connection $conn)
{ {
return new DB2SchemaManager($conn); return new DB2SchemaManager($conn);
} }
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Exception;
/** /**
* Abstract base implementation of the {@link DriverException} interface. * Abstract base implementation of the {@link DriverException} interface.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
abstract class AbstractDriverException extends \Exception implements DriverException abstract class AbstractDriverException extends Exception implements DriverException
{ {
/** /**
* The driver specific error code. * The driver specific error code.
...@@ -26,8 +26,6 @@ abstract class AbstractDriverException extends \Exception implements DriverExcep ...@@ -26,8 +26,6 @@ abstract class AbstractDriverException extends \Exception implements DriverExcep
private $sqlState; private $sqlState;
/** /**
* Constructor.
*
* @param string $message The driver error message. * @param string $message The driver error message.
* @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any. * @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any.
* @param int|string|null $errorCode The driver specific error code if any. * @param int|string|null $errorCode The driver specific error code if any.
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
...@@ -18,9 +19,7 @@ use function version_compare; ...@@ -18,9 +19,7 @@ use function version_compare;
/** /**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for MySQL based drivers. * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for MySQL based drivers.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{ {
...@@ -116,7 +115,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -116,7 +115,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
*/ */
public function createDatabasePlatformForVersion($version) public function createDatabasePlatformForVersion($version)
{ {
$mariadb = false !== stripos($version, 'mariadb'); $mariadb = stripos($version, 'mariadb') !== false;
if ($mariadb && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) { if ($mariadb && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) {
return new MariaDb1027Platform(); return new MariaDb1027Platform();
} }
...@@ -139,11 +138,12 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -139,11 +138,12 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
* returned by Oracle MySQL servers. * returned by Oracle MySQL servers.
* *
* @param string $versionString Version string returned by the driver, i.e. '5.7.10' * @param string $versionString Version string returned by the driver, i.e. '5.7.10'
*
* @throws DBALException * @throws DBALException
*/ */
private function getOracleMysqlVersionNumber(string $versionString) : string private function getOracleMysqlVersionNumber(string $versionString) : string
{ {
if ( ! preg_match( if (! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', '/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
$versionString, $versionString,
$versionParts $versionParts
...@@ -157,7 +157,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -157,7 +157,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
$minorVersion = $versionParts['minor'] ?? 0; $minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = $versionParts['patch'] ?? null; $patchVersion = $versionParts['patch'] ?? null;
if ('5' === $majorVersion && '7' === $minorVersion && null === $patchVersion) { if ($majorVersion === '5' && $minorVersion === '7' && $patchVersion === null) {
$patchVersion = '9'; $patchVersion = '9';
} }
...@@ -169,11 +169,12 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -169,11 +169,12 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
* that starts with the prefix '5.5.5-' * that starts with the prefix '5.5.5-'
* *
* @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial' * @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
*
* @throws DBALException * @throws DBALException
*/ */
private function getMariaDbMysqlVersionNumber(string $versionString) : string private function getMariaDbMysqlVersionNumber(string $versionString) : string
{ {
if ( ! preg_match( if (! preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i', '/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString, $versionString,
$versionParts $versionParts
...@@ -190,7 +191,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -190,7 +191,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();
...@@ -199,6 +200,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -199,6 +200,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return MySqlPlatform * @return MySqlPlatform
*/ */
public function getDatabasePlatform() public function getDatabasePlatform()
...@@ -208,9 +210,10 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -208,9 +210,10 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return MySqlSchemaManager * @return MySqlSchemaManager
*/ */
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) public function getSchemaManager(Connection $conn)
{ {
return new MySqlSchemaManager($conn); return new MySqlSchemaManager($conn);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString; use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
...@@ -11,9 +12,7 @@ use Doctrine\DBAL\Schema\OracleSchemaManager; ...@@ -11,9 +12,7 @@ use Doctrine\DBAL\Schema\OracleSchemaManager;
/** /**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers. * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
{ {
...@@ -63,7 +62,7 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver ...@@ -63,7 +62,7 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();
...@@ -81,7 +80,7 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver ...@@ -81,7 +80,7 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) public function getSchemaManager(Connection $conn)
{ {
return new OracleSchemaManager($conn); return new OracleSchemaManager($conn);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
...@@ -19,9 +20,7 @@ use function version_compare; ...@@ -19,9 +20,7 @@ use function version_compare;
/** /**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for PostgreSQL based drivers. * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for PostgreSQL based drivers.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{ {
...@@ -87,7 +86,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri ...@@ -87,7 +86,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
*/ */
public function createDatabasePlatformForVersion($version) public function createDatabasePlatformForVersion($version)
{ {
if ( ! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) { if (! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified( throw DBALException::invalidPlatformVersionSpecified(
$version, $version,
'<major_version>.<minor_version>.<patch_version>' '<major_version>.<minor_version>.<patch_version>'
...@@ -99,7 +98,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri ...@@ -99,7 +98,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
$patchVersion = $versionParts['patch'] ?? 0; $patchVersion = $versionParts['patch'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
switch(true) { switch (true) {
case version_compare($version, '10.0', '>='): case version_compare($version, '10.0', '>='):
return new PostgreSQL100Platform(); return new PostgreSQL100Platform();
case version_compare($version, '9.4', '>='): case version_compare($version, '9.4', '>='):
...@@ -116,7 +115,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri ...@@ -116,7 +115,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();
...@@ -134,7 +133,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri ...@@ -134,7 +133,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) public function getSchemaManager(Connection $conn)
{ {
return new PostgreSqlSchemaManager($conn); return new PostgreSqlSchemaManager($conn);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
...@@ -17,9 +18,7 @@ use function version_compare; ...@@ -17,9 +18,7 @@ use function version_compare;
/** /**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SAP Sybase SQL Anywhere based drivers. * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SAP Sybase SQL Anywhere based drivers.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{ {
...@@ -73,7 +72,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr ...@@ -73,7 +72,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
*/ */
public function createDatabasePlatformForVersion($version) public function createDatabasePlatformForVersion($version)
{ {
if ( ! preg_match( if (! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/', '/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version, $version,
$versionParts $versionParts
...@@ -90,7 +89,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr ...@@ -90,7 +89,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
$buildVersion = $versionParts['build'] ?? 0; $buildVersion = $versionParts['build'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) { switch (true) {
case version_compare($version, '16', '>='): case version_compare($version, '16', '>='):
return new SQLAnywhere16Platform(); return new SQLAnywhere16Platform();
case version_compare($version, '12', '>='): case version_compare($version, '12', '>='):
...@@ -105,7 +104,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr ...@@ -105,7 +104,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();
...@@ -123,7 +122,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr ...@@ -123,7 +122,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) public function getSchemaManager(Connection $conn)
{ {
return new SQLAnywhereSchemaManager($conn); return new SQLAnywhereSchemaManager($conn);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\SQLServer2005Platform; use Doctrine\DBAL\Platforms\SQLServer2005Platform;
...@@ -16,9 +17,7 @@ use function version_compare; ...@@ -16,9 +17,7 @@ use function version_compare;
/** /**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers. * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver
{ {
...@@ -27,7 +26,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr ...@@ -27,7 +26,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
*/ */
public function createDatabasePlatformForVersion($version) public function createDatabasePlatformForVersion($version)
{ {
if ( ! preg_match( if (! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/', '/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version, $version,
$versionParts $versionParts
...@@ -44,7 +43,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr ...@@ -44,7 +43,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
$buildVersion = $versionParts['build'] ?? 0; $buildVersion = $versionParts['build'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) { switch (true) {
case version_compare($version, '11.00.2100', '>='): case version_compare($version, '11.00.2100', '>='):
return new SQLServer2012Platform(); return new SQLServer2012Platform();
case version_compare($version, '10.00.1600', '>='): case version_compare($version, '10.00.1600', '>='):
...@@ -59,7 +58,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr ...@@ -59,7 +58,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();
...@@ -78,7 +77,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr ...@@ -78,7 +77,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) public function getSchemaManager(Connection $conn)
{ {
return new SQLServerSchemaManager($conn); return new SQLServerSchemaManager($conn);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\SqlitePlatform;
...@@ -11,9 +12,7 @@ use function strpos; ...@@ -11,9 +12,7 @@ use function strpos;
/** /**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SQLite based drivers. * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SQLite based drivers.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
{ {
...@@ -76,7 +75,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver ...@@ -76,7 +75,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();
...@@ -94,7 +93,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver ...@@ -94,7 +93,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) public function getSchemaManager(Connection $conn)
{ {
return new SqliteSchemaManager($conn); return new SqliteSchemaManager($conn);
} }
......
...@@ -9,8 +9,6 @@ use Doctrine\DBAL\ParameterType; ...@@ -9,8 +9,6 @@ use Doctrine\DBAL\ParameterType;
* Driver connections must implement this interface. * Driver connections must implement this interface.
* *
* This resembles (a subset of) the PDO interface. * This resembles (a subset of) the PDO interface.
*
* @since 2.0
*/ */
interface Connection interface Connection
{ {
...@@ -26,7 +24,7 @@ interface Connection ...@@ -26,7 +24,7 @@ interface Connection
/** /**
* Executes an SQL statement, returning a result set as a Statement object. * Executes an SQL statement, returning a result set as a Statement object.
* *
* @return \Doctrine\DBAL\Driver\Statement * @return Statement
*/ */
public function query(); public function query();
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Throwable;
/** /**
* Contract for a driver exception. * Contract for a driver exception.
* *
* Driver exceptions provide the SQLSTATE of the driver * Driver exceptions provide the SQLSTATE of the driver
* and the driver specific error code at the time the error occurred. * and the driver specific error code at the time the error occurred.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
interface DriverException extends \Throwable interface DriverException extends Throwable
{ {
/** /**
* Returns the driver specific error code if available. * Returns the driver specific error code if available.
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
namespace Doctrine\DBAL\Driver\DrizzlePDOMySql; namespace Doctrine\DBAL\Driver\DrizzlePDOMySql;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
/** class Connection extends PDOConnection
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class Connection extends \Doctrine\DBAL\Driver\PDOConnection
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
......
...@@ -7,8 +7,6 @@ use Doctrine\DBAL\Schema\DrizzleSchemaManager; ...@@ -7,8 +7,6 @@ use Doctrine\DBAL\Schema\DrizzleSchemaManager;
/** /**
* Drizzle driver using PDO MySql. * Drizzle driver using PDO MySql.
*
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/ */
class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver
{ {
...@@ -17,14 +15,12 @@ class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver ...@@ -17,14 +15,12 @@ class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver
*/ */
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{ {
$conn = new Connection( return new Connection(
$this->constructPdoDsn($params), $this->constructPdoDsn($params),
$username, $username,
$password, $password,
$driverOptions $driverOptions
); );
return $conn;
} }
/** /**
......
...@@ -5,10 +5,7 @@ namespace Doctrine\DBAL\Driver; ...@@ -5,10 +5,7 @@ namespace Doctrine\DBAL\Driver;
/** /**
* Contract for a driver that is capable of converting DBAL driver exceptions into standardized DBAL driver exceptions. * Contract for a driver that is capable of converting DBAL driver exceptions into standardized DBAL driver exceptions.
* *
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
interface ExceptionConverterDriver interface ExceptionConverterDriver
{ {
...@@ -18,8 +15,8 @@ interface ExceptionConverterDriver ...@@ -18,8 +15,8 @@ interface ExceptionConverterDriver
* It evaluates the vendor specific error code and SQLSTATE and transforms * It evaluates the vendor specific error code and SQLSTATE and transforms
* it into a unified {@link Doctrine\DBAL\Exception\DriverException} subclass. * it into a unified {@link Doctrine\DBAL\Exception\DriverException} subclass.
* *
* @param string $message The DBAL exception message to use. * @param string $message The DBAL exception message to use.
* @param \Doctrine\DBAL\Driver\DriverException $exception The DBAL driver exception to convert. * @param DriverException $exception The DBAL driver exception to convert.
* *
* @return \Doctrine\DBAL\Exception\DriverException An instance of one of the DriverException subclasses. * @return \Doctrine\DBAL\Exception\DriverException An instance of one of the DriverException subclasses.
*/ */
......
...@@ -26,9 +26,7 @@ use function func_get_args; ...@@ -26,9 +26,7 @@ use function func_get_args;
class DB2Connection implements Connection, ServerInfoAwareConnection class DB2Connection implements Connection, ServerInfoAwareConnection
{ {
/** /** @var resource */
* @var resource
*/
private $_conn = null; private $_conn = null;
/** /**
...@@ -37,18 +35,18 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -37,18 +35,18 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
* @param string $password * @param string $password
* @param array $driverOptions * @param array $driverOptions
* *
* @throws \Doctrine\DBAL\Driver\IBMDB2\DB2Exception * @throws DB2Exception
*/ */
public function __construct(array $params, $username, $password, $driverOptions = []) public function __construct(array $params, $username, $password, $driverOptions = [])
{ {
$isPersistent = (isset($params['persistent']) && $params['persistent'] == true); $isPersistent = (isset($params['persistent']) && $params['persistent'] === true);
if ($isPersistent) { if ($isPersistent) {
$this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions); $this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions);
} else { } else {
$this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions); $this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions);
} }
if ( ! $this->_conn) { if (! $this->_conn) {
throw new DB2Exception(db2_conn_errormsg()); throw new DB2Exception(db2_conn_errormsg());
} }
} }
...@@ -78,7 +76,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -78,7 +76,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
public function prepare($sql) public function prepare($sql)
{ {
$stmt = @db2_prepare($this->_conn, $sql); $stmt = @db2_prepare($this->_conn, $sql);
if ( ! $stmt) { if (! $stmt) {
throw new DB2Exception(db2_stmt_errormsg()); throw new DB2Exception(db2_stmt_errormsg());
} }
...@@ -91,7 +89,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -91,7 +89,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
public function query() public function query()
{ {
$args = func_get_args(); $args = func_get_args();
$sql = $args[0]; $sql = $args[0];
$stmt = $this->prepare($sql); $stmt = $this->prepare($sql);
$stmt->execute(); $stmt->execute();
...@@ -109,7 +107,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -109,7 +107,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
return $input; return $input;
} }
return "'".$input."'"; return "'" . $input . "'";
} }
/** /**
...@@ -119,7 +117,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -119,7 +117,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
{ {
$stmt = @db2_exec($this->_conn, $statement); $stmt = @db2_exec($this->_conn, $statement);
if (false === $stmt) { if ($stmt === false) {
throw new DB2Exception(db2_stmt_errormsg()); throw new DB2Exception(db2_stmt_errormsg());
} }
...@@ -147,7 +145,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -147,7 +145,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
*/ */
public function commit() public function commit()
{ {
if (!db2_commit($this->_conn)) { if (! db2_commit($this->_conn)) {
throw new DB2Exception(db2_conn_errormsg($this->_conn)); throw new DB2Exception(db2_conn_errormsg($this->_conn));
} }
db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON); db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
...@@ -158,7 +156,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -158,7 +156,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
*/ */
public function rollBack() public function rollBack()
{ {
if (!db2_rollback($this->_conn)) { if (! db2_rollback($this->_conn)) {
throw new DB2Exception(db2_conn_errormsg($this->_conn)); throw new DB2Exception(db2_conn_errormsg($this->_conn));
} }
db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON); db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
......
...@@ -6,9 +6,6 @@ use Doctrine\DBAL\Driver\AbstractDB2Driver; ...@@ -6,9 +6,6 @@ use Doctrine\DBAL\Driver\AbstractDB2Driver;
/** /**
* IBM DB2 Driver. * IBM DB2 Driver.
*
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class DB2Driver extends AbstractDB2Driver class DB2Driver extends AbstractDB2Driver
{ {
...@@ -17,18 +14,18 @@ class DB2Driver extends AbstractDB2Driver ...@@ -17,18 +14,18 @@ class DB2Driver extends AbstractDB2Driver
*/ */
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{ {
if ( ! isset($params['protocol'])) { if (! isset($params['protocol'])) {
$params['protocol'] = 'TCPIP'; $params['protocol'] = 'TCPIP';
} }
if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') { if ($params['host'] !== 'localhost' && $params['host'] !== '127.0.0.1') {
// if the host isn't localhost, use extended connection params // if the host isn't localhost, use extended connection params
$params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' . $params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' .
';DATABASE=' . $params['dbname'] . ';DATABASE=' . $params['dbname'] .
';HOSTNAME=' . $params['host'] . ';HOSTNAME=' . $params['host'] .
';PROTOCOL=' . $params['protocol'] . ';PROTOCOL=' . $params['protocol'] .
';UID=' . $username . ';UID=' . $username .
';PWD=' . $password .';'; ';PWD=' . $password . ';';
if (isset($params['port'])) { if (isset($params['port'])) {
$params['dbname'] .= 'PORT=' . $params['port']; $params['dbname'] .= 'PORT=' . $params['port'];
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Doctrine\DBAL\Driver\IBMDB2; namespace Doctrine\DBAL\Driver\IBMDB2;
class DB2Exception extends \Exception use Exception;
class DB2Exception extends Exception
{ {
} }
...@@ -6,6 +6,13 @@ use Doctrine\DBAL\Driver\Statement; ...@@ -6,6 +6,13 @@ use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use ReflectionClass;
use ReflectionObject;
use ReflectionProperty;
use stdClass;
use const CASE_LOWER;
use const DB2_CHAR; use const DB2_CHAR;
use const DB2_LONG; use const DB2_LONG;
use const DB2_PARAM_IN; use const DB2_PARAM_IN;
...@@ -30,31 +37,21 @@ use function ksort; ...@@ -30,31 +37,21 @@ use function ksort;
use function sprintf; use function sprintf;
use function strtolower; use function strtolower;
class DB2Statement implements \IteratorAggregate, Statement class DB2Statement implements IteratorAggregate, Statement
{ {
/** /** @var resource */
* @var resource
*/
private $_stmt; private $_stmt;
/** /** @var array */
* @var array
*/
private $_bindParam = []; private $_bindParam = [];
/** /** @var string Name of the default class to instantiate when fetching class instances. */
* @var string Name of the default class to instantiate when fetching class instances.
*/
private $defaultFetchClass = '\stdClass'; private $defaultFetchClass = '\stdClass';
/** /** @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. */
* @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
*/
private $defaultFetchClassCtorArgs = []; private $defaultFetchClassCtorArgs = [];
/** /** @var int */
* @var int
*/
private $_defaultFetchMode = FetchMode::MIXED; private $_defaultFetchMode = FetchMode::MIXED;
/** /**
...@@ -103,7 +100,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -103,7 +100,7 @@ class DB2Statement implements \IteratorAggregate, Statement
$type = DB2_CHAR; $type = DB2_CHAR;
} }
if (!db2_bind_param($this->_stmt, $column, "variable", DB2_PARAM_IN, $type)) { if (! db2_bind_param($this->_stmt, $column, 'variable', DB2_PARAM_IN, $type)) {
throw new DB2Exception(db2_stmt_errormsg()); throw new DB2Exception(db2_stmt_errormsg());
} }
...@@ -115,13 +112,13 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -115,13 +112,13 @@ class DB2Statement implements \IteratorAggregate, Statement
*/ */
public function closeCursor() public function closeCursor()
{ {
if ( ! $this->_stmt) { if (! $this->_stmt) {
return false; return false;
} }
$this->_bindParam = []; $this->_bindParam = [];
if (!db2_free_result($this->_stmt)) { if (! db2_free_result($this->_stmt)) {
return false; return false;
} }
...@@ -135,7 +132,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -135,7 +132,7 @@ class DB2Statement implements \IteratorAggregate, Statement
*/ */
public function columnCount() public function columnCount()
{ {
if ( ! $this->_stmt) { if (! $this->_stmt) {
return false; return false;
} }
...@@ -166,7 +163,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -166,7 +163,7 @@ class DB2Statement implements \IteratorAggregate, Statement
*/ */
public function execute($params = null) public function execute($params = null)
{ {
if ( ! $this->_stmt) { if (! $this->_stmt) {
return false; return false;
} }
...@@ -214,11 +211,11 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -214,11 +211,11 @@ class DB2Statement implements \IteratorAggregate, Statement
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{ {
// do not try fetching from the statement if it's not expected to contain result // do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation // in order to prevent exceptional situation
if (!$this->result) { if (! $this->result) {
return false; return false;
} }
...@@ -245,7 +242,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -245,7 +242,7 @@ class DB2Statement implements \IteratorAggregate, Statement
$result = db2_fetch_object($this->_stmt); $result = db2_fetch_object($this->_stmt);
if ($result instanceof \stdClass) { if ($result instanceof stdClass) {
$result = $this->castObject($result, $className, $ctorArgs); $result = $this->castObject($result, $className, $ctorArgs);
} }
...@@ -296,7 +293,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -296,7 +293,7 @@ class DB2Statement implements \IteratorAggregate, Statement
{ {
$row = $this->fetch(FetchMode::NUMERIC); $row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) { if ($row === false) {
return false; return false;
} }
...@@ -308,13 +305,13 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -308,13 +305,13 @@ class DB2Statement implements \IteratorAggregate, Statement
*/ */
public function rowCount() public function rowCount()
{ {
return (@db2_num_rows($this->_stmt)) ? : 0; return @db2_num_rows($this->_stmt) ? : 0;
} }
/** /**
* Casts a stdClass object to the given class name mapping its' properties. * Casts a stdClass object to the given class name mapping its' properties.
* *
* @param \stdClass $sourceObject Object to cast from. * @param stdClass $sourceObject Object to cast from.
* @param string|object $destinationClass Name of the class or class instance to cast to. * @param string|object $destinationClass Name of the class or class instance to cast to.
* @param array $ctorArgs Arguments to use for constructing the destination class instance. * @param array $ctorArgs Arguments to use for constructing the destination class instance.
* *
...@@ -322,23 +319,24 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -322,23 +319,24 @@ class DB2Statement implements \IteratorAggregate, Statement
* *
* @throws DB2Exception * @throws DB2Exception
*/ */
private function castObject(\stdClass $sourceObject, $destinationClass, array $ctorArgs = []) private function castObject(stdClass $sourceObject, $destinationClass, array $ctorArgs = [])
{ {
if ( ! is_string($destinationClass)) { if (! is_string($destinationClass)) {
if ( ! is_object($destinationClass)) { if (! is_object($destinationClass)) {
throw new DB2Exception(sprintf( throw new DB2Exception(sprintf(
'Destination class has to be of type string or object, %s given.', gettype($destinationClass) 'Destination class has to be of type string or object, %s given.',
gettype($destinationClass)
)); ));
} }
} else { } else {
$destinationClass = new \ReflectionClass($destinationClass); $destinationClass = new ReflectionClass($destinationClass);
$destinationClass = $destinationClass->newInstanceArgs($ctorArgs); $destinationClass = $destinationClass->newInstanceArgs($ctorArgs);
} }
$sourceReflection = new \ReflectionObject($sourceObject); $sourceReflection = new ReflectionObject($sourceObject);
$destinationClassReflection = new \ReflectionObject($destinationClass); $destinationClassReflection = new ReflectionObject($destinationClass);
/** @var \ReflectionProperty[] $destinationProperties */ /** @var ReflectionProperty[] $destinationProperties */
$destinationProperties = array_change_key_case($destinationClassReflection->getProperties(), \CASE_LOWER); $destinationProperties = array_change_key_case($destinationClassReflection->getProperties(), CASE_LOWER);
foreach ($sourceReflection->getProperties() as $sourceProperty) { foreach ($sourceReflection->getProperties() as $sourceProperty) {
$sourceProperty->setAccessible(true); $sourceProperty->setAccessible(true);
......
...@@ -2,12 +2,9 @@ ...@@ -2,12 +2,9 @@
namespace Doctrine\DBAL\Driver\Mysqli; namespace Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class Driver extends AbstractMySQLDriver class Driver extends AbstractMySQLDriver
{ {
/** /**
......
...@@ -6,6 +6,13 @@ use Doctrine\DBAL\Driver\Connection; ...@@ -6,6 +6,13 @@ use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\PingableConnection; use Doctrine\DBAL\Driver\PingableConnection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use mysqli;
use const MYSQLI_INIT_COMMAND;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
use const MYSQLI_OPT_LOCAL_INFILE;
use const MYSQLI_READ_DEFAULT_FILE;
use const MYSQLI_READ_DEFAULT_GROUP;
use const MYSQLI_SERVER_PUBLIC_KEY;
use function defined; use function defined;
use function floor; use function floor;
use function func_get_args; use function func_get_args;
...@@ -20,20 +27,14 @@ use function set_error_handler; ...@@ -20,20 +27,14 @@ use function set_error_handler;
use function sprintf; use function sprintf;
use function stripos; use function stripos;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
* @author Till Klampaeckel <till@php.net>
*/
class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection
{ {
/** /**
* Name of the option to set connection flags * Name of the option to set connection flags
*/ */
const OPTION_FLAGS = 'flags'; public const OPTION_FLAGS = 'flags';
/** /** @var mysqli */
* @var \mysqli
*/
private $_conn; private $_conn;
/** /**
...@@ -42,14 +43,14 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -42,14 +43,14 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
* @param string $password * @param string $password
* @param array $driverOptions * @param array $driverOptions
* *
* @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException * @throws MysqliException
*/ */
public function __construct(array $params, $username, $password, array $driverOptions = []) public function __construct(array $params, $username, $password, array $driverOptions = [])
{ {
$port = $params['port'] ?? ini_get('mysqli.default_port'); $port = $params['port'] ?? ini_get('mysqli.default_port');
// Fallback to default MySQL port if not given. // Fallback to default MySQL port if not given.
if ( ! $port) { if (! $port) {
$port = 3306; $port = 3306;
} }
...@@ -63,18 +64,21 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -63,18 +64,21 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
$this->setSecureConnection($params); $this->setSecureConnection($params);
$this->setDriverOptions($driverOptions); $this->setDriverOptions($driverOptions);
set_error_handler(function () {}); set_error_handler(static function () {
});
try { try {
if ( ! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { if (! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) {
throw new MysqliException($this->_conn->connect_error, $this->_conn->sqlstate ?? 'HY000', $this->_conn->connect_errno); throw new MysqliException($this->_conn->connect_error, $this->_conn->sqlstate ?? 'HY000', $this->_conn->connect_errno);
} }
} finally { } finally {
restore_error_handler(); restore_error_handler();
} }
if (isset($params['charset'])) { if (! isset($params['charset'])) {
$this->_conn->set_charset($params['charset']); return;
} }
$this->_conn->set_charset($params['charset']);
} }
/** /**
...@@ -82,7 +86,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -82,7 +86,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
* *
* Could be used if part of your application is not using DBAL. * Could be used if part of your application is not using DBAL.
* *
* @return \mysqli * @return mysqli
*/ */
public function getWrappedResourceHandle() public function getWrappedResourceHandle()
{ {
...@@ -94,12 +98,13 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -94,12 +98,13 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
* *
* The server version detection includes a special case for MariaDB * The server version detection includes a special case for MariaDB
* to support '5.5.5-' prefixed versions introduced in Maria 10+ * to support '5.5.5-' prefixed versions introduced in Maria 10+
*
* @link https://jira.mariadb.org/browse/MDEV-4088 * @link https://jira.mariadb.org/browse/MDEV-4088
*/ */
public function getServerVersion() public function getServerVersion()
{ {
$serverInfos = $this->_conn->get_server_info(); $serverInfos = $this->_conn->get_server_info();
if (false !== stripos($serverInfos, 'mariadb')) { if (stripos($serverInfos, 'mariadb') !== false) {
return $serverInfos; return $serverInfos;
} }
...@@ -132,7 +137,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -132,7 +137,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
public function query() public function query()
{ {
$args = func_get_args(); $args = func_get_args();
$sql = $args[0]; $sql = $args[0];
$stmt = $this->prepare($sql); $stmt = $this->prepare($sql);
$stmt->execute(); $stmt->execute();
...@@ -144,7 +149,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -144,7 +149,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*/ */
public function quote($input, $type = ParameterType::STRING) public function quote($input, $type = ParameterType::STRING)
{ {
return "'". $this->_conn->escape_string($input) ."'"; return "'" . $this->_conn->escape_string($input) . "'";
} }
/** /**
...@@ -152,7 +157,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -152,7 +157,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*/ */
public function exec($statement) public function exec($statement)
{ {
if (false === $this->_conn->query($statement)) { if ($this->_conn->query($statement) === false) {
throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno); throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno);
} }
...@@ -220,26 +225,25 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -220,26 +225,25 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
private function setDriverOptions(array $driverOptions = []) private function setDriverOptions(array $driverOptions = [])
{ {
$supportedDriverOptions = [ $supportedDriverOptions = [
\MYSQLI_OPT_CONNECT_TIMEOUT, MYSQLI_OPT_CONNECT_TIMEOUT,
\MYSQLI_OPT_LOCAL_INFILE, MYSQLI_OPT_LOCAL_INFILE,
\MYSQLI_INIT_COMMAND, MYSQLI_INIT_COMMAND,
\MYSQLI_READ_DEFAULT_FILE, MYSQLI_READ_DEFAULT_FILE,
\MYSQLI_READ_DEFAULT_GROUP, MYSQLI_READ_DEFAULT_GROUP,
]; ];
if (defined('MYSQLI_SERVER_PUBLIC_KEY')) { if (defined('MYSQLI_SERVER_PUBLIC_KEY')) {
$supportedDriverOptions[] = \MYSQLI_SERVER_PUBLIC_KEY; $supportedDriverOptions[] = MYSQLI_SERVER_PUBLIC_KEY;
} }
$exceptionMsg = "%s option '%s' with value '%s'"; $exceptionMsg = "%s option '%s' with value '%s'";
foreach ($driverOptions as $option => $value) { foreach ($driverOptions as $option => $value) {
if ($option === static::OPTION_FLAGS) { if ($option === static::OPTION_FLAGS) {
continue; continue;
} }
if (!in_array($option, $supportedDriverOptions, true)) { if (! in_array($option, $supportedDriverOptions, true)) {
throw new MysqliException( throw new MysqliException(
sprintf($exceptionMsg, 'Unsupported', $option, $value) sprintf($exceptionMsg, 'Unsupported', $option, $value)
); );
...@@ -274,6 +278,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -274,6 +278,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
* Establish a secure connection * Establish a secure connection
* *
* @param array $params * @param array $params
*
* @throws MysqliException * @throws MysqliException
*/ */
private function setSecureConnection(array $params) private function setSecureConnection(array $params)
......
...@@ -6,9 +6,6 @@ use Doctrine\DBAL\Driver\AbstractDriverException; ...@@ -6,9 +6,6 @@ use Doctrine\DBAL\Driver\AbstractDriverException;
/** /**
* Exception thrown in case the mysqli driver errors. * Exception thrown in case the mysqli driver errors.
*
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
* @author Steve Müller <st.mueller@dzh-online.de>
*/ */
class MysqliException extends AbstractDriverException class MysqliException extends AbstractDriverException
{ {
......
...@@ -7,6 +7,11 @@ use Doctrine\DBAL\Driver\StatementIterator; ...@@ -7,6 +7,11 @@ use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use mysqli;
use mysqli_stmt;
use PDO;
use stdClass;
use function array_combine; use function array_combine;
use function array_fill; use function array_fill;
use function count; use function count;
...@@ -16,14 +21,9 @@ use function get_resource_type; ...@@ -16,14 +21,9 @@ use function get_resource_type;
use function is_resource; use function is_resource;
use function str_repeat; use function str_repeat;
/** class MysqliStatement implements IteratorAggregate, Statement
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class MysqliStatement implements \IteratorAggregate, Statement
{ {
/** /** @var array */
* @var array
*/
protected static $_paramTypeMap = [ protected static $_paramTypeMap = [
ParameterType::STRING => 's', ParameterType::STRING => 's',
ParameterType::BINARY => 's', ParameterType::BINARY => 's',
...@@ -33,34 +33,22 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -33,34 +33,22 @@ class MysqliStatement implements \IteratorAggregate, Statement
ParameterType::LARGE_OBJECT => 'b', ParameterType::LARGE_OBJECT => 'b',
]; ];
/** /** @var mysqli */
* @var \mysqli
*/
protected $_conn; protected $_conn;
/** /** @var mysqli_stmt */
* @var \mysqli_stmt
*/
protected $_stmt; protected $_stmt;
/** /** @var bool|array|null */
* @var null|boolean|array
*/
protected $_columnNames; protected $_columnNames;
/** /** @var array|null */
* @var null|array
*/
protected $_rowBindedValues; protected $_rowBindedValues;
/** /** @var array */
* @var array
*/
protected $_bindedValues; protected $_bindedValues;
/** /** @var string */
* @var string
*/
protected $types; protected $types;
/** /**
...@@ -70,9 +58,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -70,9 +58,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/ */
protected $_values = []; protected $_values = [];
/** /** @var int */
* @var int
*/
protected $_defaultFetchMode = FetchMode::MIXED; protected $_defaultFetchMode = FetchMode::MIXED;
/** /**
...@@ -83,24 +69,25 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -83,24 +69,25 @@ class MysqliStatement implements \IteratorAggregate, Statement
private $result = false; private $result = false;
/** /**
* @param \mysqli $conn * @param string $prepareString
* @param string $prepareString
* *
* @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException * @throws MysqliException
*/ */
public function __construct(\mysqli $conn, $prepareString) public function __construct(mysqli $conn, $prepareString)
{ {
$this->_conn = $conn; $this->_conn = $conn;
$this->_stmt = $conn->prepare($prepareString); $this->_stmt = $conn->prepare($prepareString);
if (false === $this->_stmt) { if ($this->_stmt === false) {
throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno); throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno);
} }
$paramCount = $this->_stmt->param_count; $paramCount = $this->_stmt->param_count;
if (0 < $paramCount) { if (0 >= $paramCount) {
$this->types = str_repeat('s', $paramCount); return;
$this->_bindedValues = array_fill(1, $paramCount, null);
} }
$this->types = str_repeat('s', $paramCount);
$this->_bindedValues = array_fill(1, $paramCount, null);
} }
/** /**
...@@ -108,18 +95,18 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -108,18 +95,18 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/ */
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{ {
if (null === $type) { if ($type === null) {
$type = 's'; $type = 's';
} else { } else {
if (isset(self::$_paramTypeMap[$type])) { if (! isset(self::$_paramTypeMap[$type])) {
$type = self::$_paramTypeMap[$type];
} else {
throw new MysqliException("Unknown type: '{$type}'"); throw new MysqliException("Unknown type: '{$type}'");
} }
$type = self::$_paramTypeMap[$type];
} }
$this->_bindedValues[$column] =& $variable; $this->_bindedValues[$column] =& $variable;
$this->types[$column - 1] = $type; $this->types[$column - 1] = $type;
return true; return true;
} }
...@@ -129,19 +116,19 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -129,19 +116,19 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/ */
public function bindValue($param, $value, $type = ParameterType::STRING) public function bindValue($param, $value, $type = ParameterType::STRING)
{ {
if (null === $type) { if ($type === null) {
$type = 's'; $type = 's';
} else { } else {
if (isset(self::$_paramTypeMap[$type])) { if (! isset(self::$_paramTypeMap[$type])) {
$type = self::$_paramTypeMap[$type];
} else {
throw new MysqliException("Unknown type: '{$type}'"); throw new MysqliException("Unknown type: '{$type}'");
} }
$type = self::$_paramTypeMap[$type];
} }
$this->_values[$param] = $value; $this->_values[$param] = $value;
$this->_bindedValues[$param] =& $this->_values[$param]; $this->_bindedValues[$param] =& $this->_values[$param];
$this->types[$param - 1] = $type; $this->types[$param - 1] = $type;
return true; return true;
} }
...@@ -151,13 +138,13 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -151,13 +138,13 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/ */
public function execute($params = null) public function execute($params = null)
{ {
if (null !== $this->_bindedValues) { if ($this->_bindedValues !== null) {
if (null !== $params) { if ($params !== null) {
if ( ! $this->_bindValues($params)) { if (! $this->_bindValues($params)) {
throw new MysqliException($this->_stmt->error, $this->_stmt->errno); throw new MysqliException($this->_stmt->error, $this->_stmt->errno);
} }
} else { } else {
list($types, $values, $streams) = $this->separateBoundValues(); [$types, $values, $streams] = $this->separateBoundValues();
if (! $this->_stmt->bind_param($types, ...$values)) { if (! $this->_stmt->bind_param($types, ...$values)) {
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
} }
...@@ -165,13 +152,13 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -165,13 +152,13 @@ class MysqliStatement implements \IteratorAggregate, Statement
} }
} }
if ( ! $this->_stmt->execute()) { if (! $this->_stmt->execute()) {
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
} }
if (null === $this->_columnNames) { if ($this->_columnNames === null) {
$meta = $this->_stmt->result_metadata(); $meta = $this->_stmt->result_metadata();
if (false !== $meta) { if ($meta !== false) {
$columnNames = []; $columnNames = [];
foreach ($meta->fetch_fields() as $col) { foreach ($meta->fetch_fields() as $col) {
$columnNames[] = $col->name; $columnNames[] = $col->name;
...@@ -184,7 +171,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -184,7 +171,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
} }
} }
if (false !== $this->_columnNames) { if ($this->_columnNames !== false) {
// Store result of every execution which has it. Otherwise it will be impossible // Store result of every execution which has it. Otherwise it will be impossible
// to execute a new statement in case if the previous one has non-fetched rows // to execute a new statement in case if the previous one has non-fetched rows
// @link http://dev.mysql.com/doc/refman/5.7/en/commands-out-of-sync.html // @link http://dev.mysql.com/doc/refman/5.7/en/commands-out-of-sync.html
...@@ -285,7 +272,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -285,7 +272,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
private function _bindValues($values) private function _bindValues($values)
{ {
$params = []; $params = [];
$types = str_repeat('s', count($values)); $types = str_repeat('s', count($values));
foreach ($values as &$v) { foreach ($values as &$v) {
$params[] =& $v; $params[] =& $v;
...@@ -301,7 +288,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -301,7 +288,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
{ {
$ret = $this->_stmt->fetch(); $ret = $this->_stmt->fetch();
if (true === $ret) { if ($ret === true) {
$values = []; $values = [];
foreach ($this->_rowBindedValues as $v) { foreach ($this->_rowBindedValues as $v) {
$values[] = $v; $values[] = $v;
...@@ -316,11 +303,11 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -316,11 +303,11 @@ class MysqliStatement implements \IteratorAggregate, Statement
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{ {
// do not try fetching from the statement if it's not expected to contain result // do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation // in order to prevent exceptional situation
if (!$this->result) { if (! $this->result) {
return false; return false;
} }
...@@ -331,11 +318,11 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -331,11 +318,11 @@ class MysqliStatement implements \IteratorAggregate, Statement
} }
$values = $this->_fetch(); $values = $this->_fetch();
if (null === $values) { if ($values === null) {
return false; return false;
} }
if (false === $values) { if ($values === false) {
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
} }
...@@ -347,14 +334,14 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -347,14 +334,14 @@ class MysqliStatement implements \IteratorAggregate, Statement
return array_combine($this->_columnNames, $values); return array_combine($this->_columnNames, $values);
case FetchMode::MIXED: case FetchMode::MIXED:
$ret = array_combine($this->_columnNames, $values); $ret = array_combine($this->_columnNames, $values);
$ret += $values; $ret += $values;
return $ret; return $ret;
case FetchMode::STANDARD_OBJECT: case FetchMode::STANDARD_OBJECT:
$assoc = array_combine($this->_columnNames, $values); $assoc = array_combine($this->_columnNames, $values);
$ret = new \stdClass(); $ret = new stdClass();
foreach ($assoc as $column => $value) { foreach ($assoc as $column => $value) {
$ret->$column = $value; $ret->$column = $value;
...@@ -396,7 +383,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -396,7 +383,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
{ {
$row = $this->fetch(FetchMode::NUMERIC); $row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) { if ($row === false) {
return false; return false;
} }
...@@ -435,7 +422,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -435,7 +422,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/ */
public function rowCount() public function rowCount()
{ {
if (false === $this->_columnNames) { if ($this->_columnNames === false) {
return $this->_stmt->affected_rows; return $this->_stmt->affected_rows;
} }
......
...@@ -8,9 +8,6 @@ use const OCI_DEFAULT; ...@@ -8,9 +8,6 @@ use const OCI_DEFAULT;
/** /**
* A Doctrine DBAL driver for the Oracle OCI8 PHP extensions. * A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/ */
class Driver extends AbstractOracleDriver class Driver extends AbstractOracleDriver
{ {
......
...@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver\OCI8; ...@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use UnexpectedValueException;
use const OCI_COMMIT_ON_SUCCESS; use const OCI_COMMIT_ON_SUCCESS;
use const OCI_DEFAULT; use const OCI_DEFAULT;
use const OCI_NO_AUTO_COMMIT; use const OCI_NO_AUTO_COMMIT;
...@@ -26,19 +27,13 @@ use function str_replace; ...@@ -26,19 +27,13 @@ use function str_replace;
/** /**
* OCI8 implementation of the Connection interface. * OCI8 implementation of the Connection interface.
*
* @since 2.0
*/ */
class OCI8Connection implements Connection, ServerInfoAwareConnection class OCI8Connection implements Connection, ServerInfoAwareConnection
{ {
/** /** @var resource */
* @var resource
*/
protected $dbh; protected $dbh;
/** /** @var int */
* @var int
*/
protected $executeMode = OCI_COMMIT_ON_SUCCESS; protected $executeMode = OCI_COMMIT_ON_SUCCESS;
/** /**
...@@ -55,7 +50,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -55,7 +50,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
*/ */
public function __construct($username, $password, $db, $charset = null, $sessionMode = OCI_DEFAULT, $persistent = false) public function __construct($username, $password, $db, $charset = null, $sessionMode = OCI_DEFAULT, $persistent = false)
{ {
if (!defined('OCI_NO_AUTO_COMMIT')) { if (! defined('OCI_NO_AUTO_COMMIT')) {
define('OCI_NO_AUTO_COMMIT', 0); define('OCI_NO_AUTO_COMMIT', 0);
} }
...@@ -63,7 +58,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -63,7 +58,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
? @oci_pconnect($username, $password, $db, $charset, $sessionMode) ? @oci_pconnect($username, $password, $db, $charset, $sessionMode)
: @oci_connect($username, $password, $db, $charset, $sessionMode); : @oci_connect($username, $password, $db, $charset, $sessionMode);
if ( ! $this->dbh) { if (! $this->dbh) {
throw OCI8Exception::fromErrorInfo(oci_error()); throw OCI8Exception::fromErrorInfo(oci_error());
} }
} }
...@@ -71,13 +66,13 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -71,13 +66,13 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @throws \UnexpectedValueException if the version string returned by the database server * @throws UnexpectedValueException if the version string returned by the database server
* does not contain a parsable version number. * does not contain a parsable version number.
*/ */
public function getServerVersion() public function getServerVersion()
{ {
if ( ! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', oci_server_version($this->dbh), $version)) { if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', oci_server_version($this->dbh), $version)) {
throw new \UnexpectedValueException( throw new UnexpectedValueException(
sprintf( sprintf(
'Unexpected database version string "%s". Cannot parse an appropriate version number from it. ' . 'Unexpected database version string "%s". Cannot parse an appropriate version number from it. ' .
'Please report this database version string to the Doctrine team.', 'Please report this database version string to the Doctrine team.',
...@@ -111,7 +106,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -111,7 +106,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
public function query() public function query()
{ {
$args = func_get_args(); $args = func_get_args();
$sql = $args[0]; $sql = $args[0];
//$fetchMode = $args[1]; //$fetchMode = $args[1];
$stmt = $this->prepare($sql); $stmt = $this->prepare($sql);
$stmt->execute(); $stmt->execute();
...@@ -157,7 +152,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -157,7 +152,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
$result = $stmt->fetchColumn(); $result = $stmt->fetchColumn();
if ($result === false) { if ($result === false) {
throw new OCI8Exception("lastInsertId failed: Query was executed but no result was returned."); throw new OCI8Exception('lastInsertId failed: Query was executed but no result was returned.');
} }
return (int) $result; return (int) $result;
...@@ -188,7 +183,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -188,7 +183,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
*/ */
public function commit() public function commit()
{ {
if (!oci_commit($this->dbh)) { if (! oci_commit($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo()); throw OCI8Exception::fromErrorInfo($this->errorInfo());
} }
$this->executeMode = OCI_COMMIT_ON_SUCCESS; $this->executeMode = OCI_COMMIT_ON_SUCCESS;
...@@ -201,7 +196,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -201,7 +196,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
*/ */
public function rollBack() public function rollBack()
{ {
if (!oci_rollback($this->dbh)) { if (! oci_rollback($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo()); throw OCI8Exception::fromErrorInfo($this->errorInfo());
} }
$this->executeMode = OCI_COMMIT_ON_SUCCESS; $this->executeMode = OCI_COMMIT_ON_SUCCESS;
......
...@@ -10,8 +10,6 @@ use function func_get_args; ...@@ -10,8 +10,6 @@ use function func_get_args;
/** /**
* PDO implementation of the Connection interface. * PDO implementation of the Connection interface.
* Used by all PDO-based drivers. * Used by all PDO-based drivers.
*
* @since 2.0
*/ */
class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
{ {
...@@ -23,7 +21,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection ...@@ -23,7 +21,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
* *
* @throws PDOException in case of an error. * @throws PDOException in case of an error.
*/ */
public function __construct($dsn, $user = null, $password = null, array $options = null) public function __construct($dsn, $user = null, $password = null, ?array $options = null)
{ {
try { try {
parent::__construct($dsn, $user, $password, $options); parent::__construct($dsn, $user, $password, $options);
...@@ -71,19 +69,19 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection ...@@ -71,19 +69,19 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
*/ */
public function query() public function query()
{ {
$args = func_get_args(); $args = func_get_args();
$argsCount = count($args); $argsCount = count($args);
try { try {
if ($argsCount == 4) { if ($argsCount === 4) {
return parent::query($args[0], $args[1], $args[2], $args[3]); return parent::query($args[0], $args[1], $args[2], $args[3]);
} }
if ($argsCount == 3) { if ($argsCount === 3) {
return parent::query($args[0], $args[1], $args[2]); return parent::query($args[0], $args[1], $args[2]);
} }
if ($argsCount == 2) { if ($argsCount === 2) {
return parent::query($args[0], $args[1]); return parent::query($args[0], $args[1]);
} }
......
...@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Driver; ...@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Driver;
/** /**
* Tiny wrapper for PDOException instances to implement the {@link DriverException} interface. * Tiny wrapper for PDOException instances to implement the {@link DriverException} interface.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
class PDOException extends \PDOException implements DriverException class PDOException extends \PDOException implements DriverException
{ {
...@@ -26,8 +24,6 @@ class PDOException extends \PDOException implements DriverException ...@@ -26,8 +24,6 @@ class PDOException extends \PDOException implements DriverException
private $sqlState; private $sqlState;
/** /**
* Constructor.
*
* @param \PDOException $exception The PDO exception to wrap. * @param \PDOException $exception The PDO exception to wrap.
*/ */
public function __construct(\PDOException $exception) public function __construct(\PDOException $exception)
......
...@@ -9,11 +9,6 @@ use Doctrine\DBAL\Driver\PDOConnection; ...@@ -9,11 +9,6 @@ use Doctrine\DBAL\Driver\PDOConnection;
* Driver for the PDO IBM extension. * Driver for the PDO IBM extension.
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 1.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/ */
class Driver extends AbstractDB2Driver class Driver extends AbstractDB2Driver
{ {
...@@ -22,14 +17,12 @@ class Driver extends AbstractDB2Driver ...@@ -22,14 +17,12 @@ class Driver extends AbstractDB2Driver
*/ */
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{ {
$conn = new PDOConnection( return new PDOConnection(
$this->_constructPdoDsn($params), $this->_constructPdoDsn($params),
$username, $username,
$password, $password,
$driverOptions $driverOptions
); );
return $conn;
} }
/** /**
......
...@@ -9,8 +9,6 @@ use PDOException; ...@@ -9,8 +9,6 @@ use PDOException;
/** /**
* PDO MySql driver. * PDO MySql driver.
*
* @since 2.0
*/ */
class Driver extends AbstractMySQLDriver class Driver extends AbstractMySQLDriver
{ {
...@@ -43,7 +41,7 @@ class Driver extends AbstractMySQLDriver ...@@ -43,7 +41,7 @@ class Driver extends AbstractMySQLDriver
protected function constructPdoDsn(array $params) protected function constructPdoDsn(array $params)
{ {
$dsn = 'mysql:'; $dsn = 'mysql:';
if (isset($params['host']) && $params['host'] != '') { if (isset($params['host']) && $params['host'] !== '') {
$dsn .= 'host=' . $params['host'] . ';'; $dsn .= 'host=' . $params['host'] . ';';
} }
if (isset($params['port'])) { if (isset($params['port'])) {
......
...@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver\PDOOracle; ...@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver\PDOOracle;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractOracleDriver; use Doctrine\DBAL\Driver\AbstractOracleDriver;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use PDOException;
/** /**
* PDO Oracle driver. * PDO Oracle driver.
...@@ -28,7 +29,7 @@ class Driver extends AbstractOracleDriver ...@@ -28,7 +29,7 @@ class Driver extends AbstractOracleDriver
$password, $password,
$driverOptions $driverOptions
); );
} catch (\PDOException $e) { } catch (PDOException $e) {
throw DBALException::driverException($this, $e); throw DBALException::driverException($this, $e);
} }
} }
......
...@@ -2,17 +2,15 @@ ...@@ -2,17 +2,15 @@
namespace Doctrine\DBAL\Driver\PDOPgSql; namespace Doctrine\DBAL\Driver\PDOPgSql;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\DBALException;
use PDOException;
use PDO; use PDO;
use PDOException;
use function defined; use function defined;
/** /**
* Driver that connects through pdo_pgsql. * Driver that connects through pdo_pgsql.
*
* @since 2.0
*/ */
class Driver extends AbstractPostgreSQLDriver class Driver extends AbstractPostgreSQLDriver
{ {
...@@ -31,7 +29,7 @@ class Driver extends AbstractPostgreSQLDriver ...@@ -31,7 +29,7 @@ class Driver extends AbstractPostgreSQLDriver
if (defined('PDO::PGSQL_ATTR_DISABLE_PREPARES') if (defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')
&& (! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]) && (! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])
|| true === $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] || $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] === true
) )
) { ) {
$pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true); $pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
...@@ -62,11 +60,11 @@ class Driver extends AbstractPostgreSQLDriver ...@@ -62,11 +60,11 @@ class Driver extends AbstractPostgreSQLDriver
{ {
$dsn = 'pgsql:'; $dsn = 'pgsql:';
if (isset($params['host']) && $params['host'] != '') { if (isset($params['host']) && $params['host'] !== '') {
$dsn .= 'host=' . $params['host'] . ';'; $dsn .= 'host=' . $params['host'] . ';';
} }
if (isset($params['port']) && $params['port'] != '') { if (isset($params['port']) && $params['port'] !== '') {
$dsn .= 'port=' . $params['port'] . ';'; $dsn .= 'port=' . $params['port'] . ';';
} }
......
...@@ -10,14 +10,10 @@ use function array_merge; ...@@ -10,14 +10,10 @@ use function array_merge;
/** /**
* The PDO Sqlite driver. * The PDO Sqlite driver.
*
* @since 2.0
*/ */
class Driver extends AbstractSQLiteDriver class Driver extends AbstractSQLiteDriver
{ {
/** /** @var array */
* @var array
*/
protected $_userDefinedFunctions = [ protected $_userDefinedFunctions = [
'sqrt' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfSqrt'], 'numArgs' => 1], 'sqrt' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfSqrt'], 'numArgs' => 1],
'mod' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfMod'], 'numArgs' => 2], 'mod' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfMod'], 'numArgs' => 2],
...@@ -31,7 +27,9 @@ class Driver extends AbstractSQLiteDriver ...@@ -31,7 +27,9 @@ class Driver extends AbstractSQLiteDriver
{ {
if (isset($driverOptions['userDefinedFunctions'])) { if (isset($driverOptions['userDefinedFunctions'])) {
$this->_userDefinedFunctions = array_merge( $this->_userDefinedFunctions = array_merge(
$this->_userDefinedFunctions, $driverOptions['userDefinedFunctions']); $this->_userDefinedFunctions,
$driverOptions['userDefinedFunctions']
);
unset($driverOptions['userDefinedFunctions']); unset($driverOptions['userDefinedFunctions']);
} }
......
...@@ -4,23 +4,22 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; ...@@ -4,23 +4,22 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use PDO;
use function strpos; use function strpos;
use function substr; use function substr;
/** /**
* Sqlsrv Connection implementation. * Sqlsrv Connection implementation.
*
* @since 2.0
*/ */
class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connection class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connection
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct($dsn, $user = null, $password = null, array $options = null) public function __construct($dsn, $user = null, $password = null, ?array $options = null)
{ {
parent::__construct($dsn, $user, $password, $options); parent::__construct($dsn, $user, $password, $options);
$this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
} }
/** /**
...@@ -28,7 +27,7 @@ class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connecti ...@@ -28,7 +27,7 @@ class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connecti
*/ */
public function lastInsertId($name = null) public function lastInsertId($name = null)
{ {
if (null === $name) { if ($name === null) {
return parent::lastInsertId($name); return parent::lastInsertId($name);
} }
......
...@@ -8,8 +8,6 @@ use function sprintf; ...@@ -8,8 +8,6 @@ use function sprintf;
/** /**
* The PDO-based Sqlsrv driver. * The PDO-based Sqlsrv driver.
*
* @since 2.0
*/ */
class Driver extends AbstractSQLServerDriver class Driver extends AbstractSQLServerDriver
{ {
...@@ -31,7 +29,7 @@ class Driver extends AbstractSQLServerDriver ...@@ -31,7 +29,7 @@ class Driver extends AbstractSQLServerDriver
/** /**
* Constructs the Sqlsrv PDO DSN. * Constructs the Sqlsrv PDO DSN.
* *
* @param array $params * @param array $params
* @param string[] $connectionOptions * @param string[] $connectionOptions
* *
* @return string The DSN. * @return string The DSN.
...@@ -44,7 +42,7 @@ class Driver extends AbstractSQLServerDriver ...@@ -44,7 +42,7 @@ class Driver extends AbstractSQLServerDriver
$dsn .= $params['host']; $dsn .= $params['host'];
} }
if (isset($params['port']) && !empty($params['port'])) { if (isset($params['port']) && ! empty($params['port'])) {
$dsn .= ',' . $params['port']; $dsn .= ',' . $params['port'];
} }
...@@ -65,6 +63,7 @@ class Driver extends AbstractSQLServerDriver ...@@ -65,6 +63,7 @@ class Driver extends AbstractSQLServerDriver
* Separates a connection options from a driver options * Separates a connection options from a driver options
* *
* @param int[]|string[] $options * @param int[]|string[] $options
*
* @return int[][]|string[][] * @return int[][]|string[][]
*/ */
private function splitOptions(array $options) : array private function splitOptions(array $options) : array
......
...@@ -12,14 +12,9 @@ use function trigger_error; ...@@ -12,14 +12,9 @@ use function trigger_error;
/** /**
* The PDO implementation of the Statement interface. * The PDO implementation of the Statement interface.
* Used by all PDO-based drivers. * Used by all PDO-based drivers.
*
* @since 2.0
*/ */
class PDOStatement extends \PDOStatement implements Statement class PDOStatement extends \PDOStatement implements Statement
{ {
/**
* @var int[]
*/
private const PARAM_TYPE_MAP = [ private const PARAM_TYPE_MAP = [
ParameterType::NULL => PDO::PARAM_NULL, ParameterType::NULL => PDO::PARAM_NULL,
ParameterType::INTEGER => PDO::PARAM_INT, ParameterType::INTEGER => PDO::PARAM_INT,
...@@ -29,9 +24,6 @@ class PDOStatement extends \PDOStatement implements Statement ...@@ -29,9 +24,6 @@ class PDOStatement extends \PDOStatement implements Statement
ParameterType::BOOLEAN => PDO::PARAM_BOOL, ParameterType::BOOLEAN => PDO::PARAM_BOOL,
]; ];
/**
* @var int[]
*/
private const FETCH_MODE_MAP = [ private const FETCH_MODE_MAP = [
FetchMode::ASSOCIATIVE => PDO::FETCH_ASSOC, FetchMode::ASSOCIATIVE => PDO::FETCH_ASSOC,
FetchMode::NUMERIC => PDO::FETCH_NUM, FetchMode::NUMERIC => PDO::FETCH_NUM,
...@@ -131,20 +123,20 @@ class PDOStatement extends \PDOStatement implements Statement ...@@ -131,20 +123,20 @@ class PDOStatement extends \PDOStatement implements Statement
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{ {
$fetchMode = $this->convertFetchMode($fetchMode); $fetchMode = $this->convertFetchMode($fetchMode);
try { try {
if ($fetchMode === null && \PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) { if ($fetchMode === null && $cursorOrientation === PDO::FETCH_ORI_NEXT && $cursorOffset === 0) {
return parent::fetch(); return parent::fetch();
} }
if (\PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) { if ($cursorOrientation === PDO::FETCH_ORI_NEXT && $cursorOffset === 0) {
return parent::fetch($fetchMode); return parent::fetch($fetchMode);
} }
if (0 === $cursorOffset) { if ($cursorOffset === 0) {
return parent::fetch($fetchMode, $cursorOrientation); return parent::fetch($fetchMode, $cursorOrientation);
} }
...@@ -162,15 +154,15 @@ class PDOStatement extends \PDOStatement implements Statement ...@@ -162,15 +154,15 @@ class PDOStatement extends \PDOStatement implements Statement
$fetchMode = $this->convertFetchMode($fetchMode); $fetchMode = $this->convertFetchMode($fetchMode);
try { try {
if ($fetchMode === null && null === $fetchArgument && null === $ctorArgs) { if ($fetchMode === null && $fetchArgument === null && $ctorArgs === null) {
return parent::fetchAll(); return parent::fetchAll();
} }
if (null === $fetchArgument && null === $ctorArgs) { if ($fetchArgument === null && $ctorArgs === null) {
return parent::fetchAll($fetchMode); return parent::fetchAll($fetchMode);
} }
if (null === $ctorArgs) { if ($ctorArgs === null) {
return parent::fetchAll($fetchMode, $fetchArgument); return parent::fetchAll($fetchMode, $fetchArgument);
} }
......
...@@ -6,9 +6,6 @@ namespace Doctrine\DBAL\Driver; ...@@ -6,9 +6,6 @@ namespace Doctrine\DBAL\Driver;
* An interface for connections which support a "native" ping method. * An interface for connections which support a "native" ping method.
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
* @author Till Klampaeckel <till@php.net>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
interface PingableConnection interface PingableConnection
{ {
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use PDO;
use Traversable;
/** /**
* Interface for the reading part of a prepare statement only. * Interface for the reading part of a prepare statement only.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
interface ResultStatement extends \Traversable interface ResultStatement extends Traversable
{ {
/** /**
* Closes the cursor, enabling the statement to be executed again. * Closes the cursor, enabling the statement to be executed again.
...@@ -61,7 +62,7 @@ interface ResultStatement extends \Traversable ...@@ -61,7 +62,7 @@ interface ResultStatement extends \Traversable
* @return mixed The return value of this method on success depends on the fetch mode. In all cases, FALSE is * @return mixed The return value of this method on success depends on the fetch mode. In all cases, FALSE is
* returned on failure. * returned on failure.
*/ */
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0); public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0);
/** /**
* Returns an array containing all of the result set rows. * Returns an array containing all of the result set rows.
...@@ -92,7 +93,7 @@ interface ResultStatement extends \Traversable ...@@ -92,7 +93,7 @@ interface ResultStatement extends \Traversable
* If no value is supplied, PDOStatement->fetchColumn() * If no value is supplied, PDOStatement->fetchColumn()
* fetches the first column. * fetches the first column.
* *
* @return string|boolean A single column in the next row of a result set, or FALSE if there are no more rows. * @return string|bool A single column in the next row of a result set, or FALSE if there are no more rows.
*/ */
public function fetchColumn($columnIndex = 0); public function fetchColumn($columnIndex = 0);
} }
...@@ -11,16 +11,14 @@ use function implode; ...@@ -11,16 +11,14 @@ use function implode;
/** /**
* A Doctrine DBAL driver for the SAP Sybase SQL Anywhere PHP extension. * A Doctrine DBAL driver for the SAP Sybase SQL Anywhere PHP extension.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
class Driver extends AbstractSQLAnywhereDriver class Driver extends AbstractSQLAnywhereDriver
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @throws \Doctrine\DBAL\DBALException if there was a problem establishing the connection. * @throws DBALException if there was a problem establishing the connection.
*/ */
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{ {
...@@ -74,15 +72,14 @@ class Driver extends AbstractSQLAnywhereDriver ...@@ -74,15 +72,14 @@ class Driver extends AbstractSQLAnywhereDriver
$server = ';ServerName=' . $server; $server = ';ServerName=' . $server;
} }
return return 'HOST=' . $host . ':' . $port .
'HOST=' . $host . ':' . $port .
$server . $server .
';DBN=' . $dbname . ';DBN=' . $dbname .
';UID=' . $username . ';UID=' . $username .
';PWD=' . $password . ';PWD=' . $password .
';' . implode( ';' . implode(
';', ';',
array_map(function ($key, $value) { array_map(static function ($key, $value) {
return $key . '=' . $value; return $key . '=' . $value;
}, array_keys($driverOptions), $driverOptions) }, array_keys($driverOptions), $driverOptions)
); );
......
...@@ -26,20 +26,14 @@ use function sasql_set_option; ...@@ -26,20 +26,14 @@ use function sasql_set_option;
/** /**
* SAP Sybase SQL Anywhere implementation of the Connection interface. * SAP Sybase SQL Anywhere implementation of the Connection interface.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
{ {
/** /** @var resource The SQL Anywhere connection resource. */
* @var resource The SQL Anywhere connection resource.
*/
private $connection; private $connection;
/** /**
* Constructor.
*
* Connects to database with given connection string. * Connects to database with given connection string.
* *
* @param string $dsn The connection string. * @param string $dsn The connection string.
...@@ -51,22 +45,22 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -51,22 +45,22 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
{ {
$this->connection = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn); $this->connection = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn);
if ( ! is_resource($this->connection)) { if (! is_resource($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError(); throw SQLAnywhereException::fromSQLAnywhereError();
} }
// Disable PHP warnings on error. // Disable PHP warnings on error.
if ( ! sasql_set_option($this->connection, 'verbose_errors', false)) { if (! sasql_set_option($this->connection, 'verbose_errors', false)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
// Enable auto committing by default. // Enable auto committing by default.
if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) { if (! sasql_set_option($this->connection, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
// Enable exact, non-approximated row count retrieval. // Enable exact, non-approximated row count retrieval.
if ( ! sasql_set_option($this->connection, 'row_counts', true)) { if (! sasql_set_option($this->connection, 'row_counts', true)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
} }
...@@ -78,7 +72,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -78,7 +72,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/ */
public function beginTransaction() public function beginTransaction()
{ {
if ( ! sasql_set_option($this->connection, 'auto_commit', 'off')) { if (! sasql_set_option($this->connection, 'auto_commit', 'off')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
...@@ -92,7 +86,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -92,7 +86,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/ */
public function commit() public function commit()
{ {
if ( ! sasql_commit($this->connection)) { if (! sasql_commit($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
...@@ -122,7 +116,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -122,7 +116,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/ */
public function exec($statement) public function exec($statement)
{ {
if (false === sasql_real_query($this->connection, $statement)) { if (sasql_real_query($this->connection, $statement) === false) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
...@@ -146,7 +140,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -146,7 +140,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/ */
public function lastInsertId($name = null) public function lastInsertId($name = null)
{ {
if (null === $name) { if ($name === null) {
return sasql_insert_id($this->connection); return sasql_insert_id($this->connection);
} }
...@@ -201,7 +195,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -201,7 +195,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/ */
public function rollBack() public function rollBack()
{ {
if ( ! sasql_rollback($this->connection)) { if (! sasql_rollback($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
...@@ -213,13 +207,13 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -213,13 +207,13 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
/** /**
* Ends transactional mode and enables auto commit again. * Ends transactional mode and enables auto commit again.
* *
* @throws SQLAnywhereException
*
* @return bool Whether or not ending transactional mode succeeded. * @return bool Whether or not ending transactional mode succeeded.
*
* @throws SQLAnywhereException
*/ */
private function endTransaction() private function endTransaction()
{ {
if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) { if (! sasql_set_option($this->connection, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Driver\SQLAnywhere; namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\AbstractDriverException; use Doctrine\DBAL\Driver\AbstractDriverException;
use InvalidArgumentException;
use function is_resource; use function is_resource;
use function sasql_error; use function sasql_error;
use function sasql_errorcode; use function sasql_errorcode;
...@@ -13,9 +14,7 @@ use function sasql_stmt_error; ...@@ -13,9 +14,7 @@ use function sasql_stmt_error;
/** /**
* SAP Sybase SQL Anywhere driver exception. * SAP Sybase SQL Anywhere driver exception.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
class SQLAnywhereException extends AbstractDriverException class SQLAnywhereException extends AbstractDriverException
{ {
...@@ -27,16 +26,16 @@ class SQLAnywhereException extends AbstractDriverException ...@@ -27,16 +26,16 @@ class SQLAnywhereException extends AbstractDriverException
* *
* @return SQLAnywhereException * @return SQLAnywhereException
* *
* @throws \InvalidArgumentException * @throws InvalidArgumentException
*/ */
public static function fromSQLAnywhereError($conn = null, $stmt = null) public static function fromSQLAnywhereError($conn = null, $stmt = null)
{ {
if (null !== $conn && ! (is_resource($conn))) { if ($conn !== null && ! is_resource($conn)) {
throw new \InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn); throw new InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn);
} }
if (null !== $stmt && ! (is_resource($stmt))) { if ($stmt !== null && ! is_resource($stmt)) {
throw new \InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt); throw new InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt);
} }
$state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate(); $state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate();
...@@ -69,7 +68,7 @@ class SQLAnywhereException extends AbstractDriverException ...@@ -69,7 +68,7 @@ class SQLAnywhereException extends AbstractDriverException
* or the last error could not be retrieved from the given * or the last error could not be retrieved from the given
* connection / statement resource. * connection / statement resource.
*/ */
if ( ! $conn || ! $code) { if (! $conn || ! $code) {
$code = sasql_errorcode(); $code = sasql_errorcode();
$message = sasql_error(); $message = sasql_error();
} }
......
...@@ -7,6 +7,10 @@ use Doctrine\DBAL\Driver\StatementIterator; ...@@ -7,6 +7,10 @@ use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate; use IteratorAggregate;
use PDO;
use ReflectionClass;
use ReflectionObject;
use stdClass;
use const SASQL_BOTH; use const SASQL_BOTH;
use function array_key_exists; use function array_key_exists;
use function func_get_args; use function func_get_args;
...@@ -35,45 +39,29 @@ use function sprintf; ...@@ -35,45 +39,29 @@ use function sprintf;
/** /**
* SAP SQL Anywhere implementation of the Statement interface. * SAP SQL Anywhere implementation of the Statement interface.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
class SQLAnywhereStatement implements IteratorAggregate, Statement class SQLAnywhereStatement implements IteratorAggregate, Statement
{ {
/** /** @var resource The connection resource. */
* @var resource The connection resource.
*/
private $conn; private $conn;
/** /** @var string Name of the default class to instantiate when fetching class instances. */
* @var string Name of the default class to instantiate when fetching class instances.
*/
private $defaultFetchClass = '\stdClass'; private $defaultFetchClass = '\stdClass';
/** /** @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. */
* @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
*/
private $defaultFetchClassCtorArgs = []; private $defaultFetchClassCtorArgs = [];
/** /** @var int Default fetch mode to use. */
* @var int Default fetch mode to use.
*/
private $defaultFetchMode = FetchMode::MIXED; private $defaultFetchMode = FetchMode::MIXED;
/** /** @var resource The result set resource to fetch. */
* @var resource The result set resource to fetch.
*/
private $result; private $result;
/** /** @var resource The prepared SQL statement to execute. */
* @var resource The prepared SQL statement to execute.
*/
private $stmt; private $stmt;
/** /**
* Constructor.
*
* Prepares given statement for given connection. * Prepares given statement for given connection.
* *
* @param resource $conn The connection resource to use. * @param resource $conn The connection resource to use.
...@@ -83,14 +71,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -83,14 +71,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/ */
public function __construct($conn, $sql) public function __construct($conn, $sql)
{ {
if ( ! is_resource($conn)) { if (! is_resource($conn)) {
throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn); throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn);
} }
$this->conn = $conn; $this->conn = $conn;
$this->stmt = sasql_prepare($conn, $sql); $this->stmt = sasql_prepare($conn, $sql);
if ( ! is_resource($this->stmt)) { if (! is_resource($this->stmt)) {
throw SQLAnywhereException::fromSQLAnywhereError($conn); throw SQLAnywhereException::fromSQLAnywhereError($conn);
} }
} }
...@@ -122,7 +110,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -122,7 +110,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
throw new SQLAnywhereException('Unknown type: ' . $type); throw new SQLAnywhereException('Unknown type: ' . $type);
} }
if ( ! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) { if (! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt); throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
} }
...@@ -144,7 +132,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -144,7 +132,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/ */
public function closeCursor() public function closeCursor()
{ {
if (!sasql_stmt_reset($this->stmt)) { if (! sasql_stmt_reset($this->stmt)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt); throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
} }
...@@ -186,13 +174,13 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -186,13 +174,13 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$hasZeroIndex = array_key_exists(0, $params); $hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) { foreach ($params as $key => $val) {
$key = ($hasZeroIndex && is_numeric($key)) ? $key + 1 : $key; $key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key;
$this->bindValue($key, $val); $this->bindValue($key, $val);
} }
} }
if ( ! sasql_stmt_execute($this->stmt)) { if (! sasql_stmt_execute($this->stmt)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt); throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
} }
...@@ -206,9 +194,9 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -206,9 +194,9 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
* *
* @throws SQLAnywhereException * @throws SQLAnywhereException
*/ */
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{ {
if ( ! is_resource($this->result)) { if (! is_resource($this->result)) {
return false; return false;
} }
...@@ -236,7 +224,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -236,7 +224,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$result = sasql_fetch_object($this->result); $result = sasql_fetch_object($this->result);
if ($result instanceof \stdClass) { if ($result instanceof stdClass) {
$result = $this->castObject($result, $className, $ctorArgs); $result = $this->castObject($result, $className, $ctorArgs);
} }
...@@ -289,7 +277,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -289,7 +277,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
{ {
$row = $this->fetch(FetchMode::NUMERIC); $row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) { if ($row === false) {
return false; return false;
} }
...@@ -325,7 +313,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -325,7 +313,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
/** /**
* Casts a stdClass object to the given class name mapping its' properties. * Casts a stdClass object to the given class name mapping its' properties.
* *
* @param \stdClass $sourceObject Object to cast from. * @param stdClass $sourceObject Object to cast from.
* @param string|object $destinationClass Name of the class or class instance to cast to. * @param string|object $destinationClass Name of the class or class instance to cast to.
* @param array $ctorArgs Arguments to use for constructing the destination class instance. * @param array $ctorArgs Arguments to use for constructing the destination class instance.
* *
...@@ -333,21 +321,22 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -333,21 +321,22 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
* *
* @throws SQLAnywhereException * @throws SQLAnywhereException
*/ */
private function castObject(\stdClass $sourceObject, $destinationClass, array $ctorArgs = []) private function castObject(stdClass $sourceObject, $destinationClass, array $ctorArgs = [])
{ {
if ( ! is_string($destinationClass)) { if (! is_string($destinationClass)) {
if ( ! is_object($destinationClass)) { if (! is_object($destinationClass)) {
throw new SQLAnywhereException(sprintf( throw new SQLAnywhereException(sprintf(
'Destination class has to be of type string or object, %s given.', gettype($destinationClass) 'Destination class has to be of type string or object, %s given.',
gettype($destinationClass)
)); ));
} }
} else { } else {
$destinationClass = new \ReflectionClass($destinationClass); $destinationClass = new ReflectionClass($destinationClass);
$destinationClass = $destinationClass->newInstanceArgs($ctorArgs); $destinationClass = $destinationClass->newInstanceArgs($ctorArgs);
} }
$sourceReflection = new \ReflectionObject($sourceObject); $sourceReflection = new ReflectionObject($sourceObject);
$destinationClassReflection = new \ReflectionObject($destinationClass); $destinationClassReflection = new ReflectionObject($destinationClass);
foreach ($sourceReflection->getProperties() as $sourceProperty) { foreach ($sourceReflection->getProperties() as $sourceProperty) {
$sourceProperty->setAccessible(true); $sourceProperty->setAccessible(true);
......
...@@ -14,7 +14,7 @@ class Driver extends AbstractSQLServerDriver ...@@ -14,7 +14,7 @@ class Driver extends AbstractSQLServerDriver
*/ */
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{ {
if (!isset($params['host'])) { if (! isset($params['host'])) {
throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver."); throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver.");
} }
...@@ -26,7 +26,7 @@ class Driver extends AbstractSQLServerDriver ...@@ -26,7 +26,7 @@ class Driver extends AbstractSQLServerDriver
if (isset($params['dbname'])) { if (isset($params['dbname'])) {
$driverOptions['Database'] = $params['dbname']; $driverOptions['Database'] = $params['dbname'];
} }
if (isset($params['charset'])) { if (isset($params['charset'])) {
$driverOptions['CharacterSet'] = $params['charset']; $driverOptions['CharacterSet'] = $params['charset'];
} }
...@@ -34,7 +34,7 @@ class Driver extends AbstractSQLServerDriver ...@@ -34,7 +34,7 @@ class Driver extends AbstractSQLServerDriver
$driverOptions['UID'] = $username; $driverOptions['UID'] = $username;
$driverOptions['PWD'] = $password; $driverOptions['PWD'] = $password;
if (!isset($driverOptions['ReturnDatesAsStrings'])) { if (! isset($driverOptions['ReturnDatesAsStrings'])) {
$driverOptions['ReturnDatesAsStrings'] = 1; $driverOptions['ReturnDatesAsStrings'] = 1;
} }
......
...@@ -4,15 +4,10 @@ namespace Doctrine\DBAL\Driver\SQLSrv; ...@@ -4,15 +4,10 @@ namespace Doctrine\DBAL\Driver\SQLSrv;
/** /**
* Last Id Data Container. * Last Id Data Container.
*
* @since 2.3
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class LastInsertId class LastInsertId
{ {
/** /** @var int */
* @var int
*/
private $id; private $id;
/** /**
......
...@@ -23,36 +23,29 @@ use function str_replace; ...@@ -23,36 +23,29 @@ use function str_replace;
/** /**
* SQL Server implementation for the Connection interface. * SQL Server implementation for the Connection interface.
*
* @since 2.3
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class SQLSrvConnection implements Connection, ServerInfoAwareConnection class SQLSrvConnection implements Connection, ServerInfoAwareConnection
{ {
/** /** @var resource */
* @var resource
*/
protected $conn; protected $conn;
/** /** @var LastInsertId */
* @var \Doctrine\DBAL\Driver\SQLSrv\LastInsertId
*/
protected $lastInsertId; protected $lastInsertId;
/** /**
* @param string $serverName * @param string $serverName
* @param array $connectionOptions * @param array $connectionOptions
* *
* @throws \Doctrine\DBAL\Driver\SQLSrv\SQLSrvException * @throws SQLSrvException
*/ */
public function __construct($serverName, $connectionOptions) public function __construct($serverName, $connectionOptions)
{ {
if ( ! sqlsrv_configure('WarningsReturnAsErrors', 0)) { if (! sqlsrv_configure('WarningsReturnAsErrors', 0)) {
throw SQLSrvException::fromSqlSrvErrors(); throw SQLSrvException::fromSqlSrvErrors();
} }
$this->conn = sqlsrv_connect($serverName, $connectionOptions); $this->conn = sqlsrv_connect($serverName, $connectionOptions);
if ( ! $this->conn) { if (! $this->conn) {
throw SQLSrvException::fromSqlSrvErrors(); throw SQLSrvException::fromSqlSrvErrors();
} }
$this->lastInsertId = new LastInsertId(); $this->lastInsertId = new LastInsertId();
...@@ -90,7 +83,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection ...@@ -90,7 +83,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
public function query() public function query()
{ {
$args = func_get_args(); $args = func_get_args();
$sql = $args[0]; $sql = $args[0];
$stmt = $this->prepare($sql); $stmt = $this->prepare($sql);
$stmt->execute(); $stmt->execute();
...@@ -99,7 +92,6 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection ...@@ -99,7 +92,6 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
/** /**
* {@inheritDoc} * {@inheritDoc}
* @license New BSD, code from Zend Framework
*/ */
public function quote($value, $type = ParameterType::STRING) public function quote($value, $type = ParameterType::STRING)
{ {
...@@ -119,7 +111,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection ...@@ -119,7 +111,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
{ {
$stmt = sqlsrv_query($this->conn, $statement); $stmt = sqlsrv_query($this->conn, $statement);
if (false === $stmt) { if ($stmt === false) {
throw SQLSrvException::fromSqlSrvErrors(); throw SQLSrvException::fromSqlSrvErrors();
} }
...@@ -146,7 +138,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection ...@@ -146,7 +138,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
*/ */
public function beginTransaction() public function beginTransaction()
{ {
if ( ! sqlsrv_begin_transaction($this->conn)) { if (! sqlsrv_begin_transaction($this->conn)) {
throw SQLSrvException::fromSqlSrvErrors(); throw SQLSrvException::fromSqlSrvErrors();
} }
} }
...@@ -156,7 +148,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection ...@@ -156,7 +148,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
*/ */
public function commit() public function commit()
{ {
if ( ! sqlsrv_commit($this->conn)) { if (! sqlsrv_commit($this->conn)) {
throw SQLSrvException::fromSqlSrvErrors(); throw SQLSrvException::fromSqlSrvErrors();
} }
} }
...@@ -166,7 +158,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection ...@@ -166,7 +158,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
*/ */
public function rollBack() public function rollBack()
{ {
if ( ! sqlsrv_rollback($this->conn)) { if (! sqlsrv_rollback($this->conn)) {
throw SQLSrvException::fromSqlSrvErrors(); throw SQLSrvException::fromSqlSrvErrors();
} }
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace Doctrine\DBAL\Driver\SQLSrv; namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\AbstractDriverException; use Doctrine\DBAL\Driver\AbstractDriverException;
use const SQLSRV_ERR_ERRORS; use const SQLSRV_ERR_ERRORS;
use function rtrim; use function rtrim;
...@@ -17,24 +16,26 @@ class SQLSrvException extends AbstractDriverException ...@@ -17,24 +16,26 @@ class SQLSrvException extends AbstractDriverException
*/ */
public static function fromSqlSrvErrors() public static function fromSqlSrvErrors()
{ {
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
$message = ""; $message = '';
$sqlState = null; $sqlState = null;
$errorCode = null; $errorCode = null;
foreach ($errors as $error) { foreach ($errors as $error) {
$message .= "SQLSTATE [".$error['SQLSTATE'].", ".$error['code']."]: ". $error['message']."\n"; $message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n";
if (null === $sqlState) { if ($sqlState === null) {
$sqlState = $error['SQLSTATE']; $sqlState = $error['SQLSTATE'];
} }
if (null === $errorCode) { if ($errorCode !== null) {
$errorCode = $error['code']; continue;
} }
$errorCode = $error['code'];
} }
if ( ! $message) { if (! $message) {
$message = "SQL Server error occurred but no error message was retrieved from driver."; $message = 'SQL Server error occurred but no error message was retrieved from driver.';
} }
return new self(rtrim($message), $sqlState, $errorCode); return new self(rtrim($message), $sqlState, $errorCode);
......
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
namespace Doctrine\DBAL\Driver\SQLSrv; namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate; use IteratorAggregate;
use Doctrine\DBAL\Driver\Statement; use PDO;
use const SQLSRV_ENC_BINARY; use const SQLSRV_ENC_BINARY;
use const SQLSRV_ERR_ERRORS; use const SQLSRV_ERR_ERRORS;
use const SQLSRV_FETCH_ASSOC; use const SQLSRV_FETCH_ASSOC;
...@@ -35,9 +36,6 @@ use function stripos; ...@@ -35,9 +36,6 @@ use function stripos;
/** /**
* SQL Server Statement. * SQL Server Statement.
*
* @since 2.3
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class SQLSrvStatement implements IteratorAggregate, Statement class SQLSrvStatement implements IteratorAggregate, Statement
{ {
...@@ -111,7 +109,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -111,7 +109,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/** /**
* The last insert ID. * The last insert ID.
* *
* @var \Doctrine\DBAL\Driver\SQLSrv\LastInsertId|null * @var LastInsertId|null
*/ */
private $lastInsertId; private $lastInsertId;
...@@ -124,25 +122,24 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -124,25 +122,24 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/** /**
* Append to any INSERT query to retrieve the last insert id. * Append to any INSERT query to retrieve the last insert id.
*
* @var string
*/ */
const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;'; public const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;';
/** /**
* @param resource $conn * @param resource $conn
* @param string $sql * @param string $sql
* @param \Doctrine\DBAL\Driver\SQLSrv\LastInsertId|null $lastInsertId
*/ */
public function __construct($conn, $sql, LastInsertId $lastInsertId = null) public function __construct($conn, $sql, ?LastInsertId $lastInsertId = null)
{ {
$this->conn = $conn; $this->conn = $conn;
$this->sql = $sql; $this->sql = $sql;
if (stripos($sql, 'INSERT INTO ') === 0) { if (stripos($sql, 'INSERT INTO ') !== 0) {
$this->sql .= self::LAST_INSERT_ID_SQL; return;
$this->lastInsertId = $lastInsertId;
} }
$this->sql .= self::LAST_INSERT_ID_SQL;
$this->lastInsertId = $lastInsertId;
} }
/** /**
...@@ -150,14 +147,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -150,14 +147,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/ */
public function bindValue($param, $value, $type = ParameterType::STRING) public function bindValue($param, $value, $type = ParameterType::STRING)
{ {
if (!is_numeric($param)) { if (! is_numeric($param)) {
throw new SQLSrvException( throw new SQLSrvException(
'sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.' 'sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.'
); );
} }
$this->variables[$param] = $value; $this->variables[$param] = $value;
$this->types[$param] = $type; $this->types[$param] = $type;
} }
/** /**
...@@ -165,12 +162,12 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -165,12 +162,12 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/ */
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{ {
if (!is_numeric($column)) { if (! is_numeric($column)) {
throw new SQLSrvException("sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead."); throw new SQLSrvException('sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.');
} }
$this->variables[$column] =& $variable; $this->variables[$column] =& $variable;
$this->types[$column] = $type; $this->types[$column] = $type;
// unset the statement resource if it exists as the new one will need to be bound to the new variable // unset the statement resource if it exists as the new one will need to be bound to the new variable
$this->stmt = null; $this->stmt = null;
...@@ -182,7 +179,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -182,7 +179,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
public function closeCursor() public function closeCursor()
{ {
// not having the result means there's nothing to close // not having the result means there's nothing to close
if (!$this->result) { if (! $this->result) {
return true; return true;
} }
...@@ -190,7 +187,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -190,7 +187,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
// @link http://php.net/manual/en/pdostatement.closecursor.php // @link http://php.net/manual/en/pdostatement.closecursor.php
// @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075 // @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
// deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them // deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
while (sqlsrv_fetch($this->stmt)); while (sqlsrv_fetch($this->stmt)) {
}
$this->result = false; $this->result = false;
...@@ -234,16 +232,16 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -234,16 +232,16 @@ class SQLSrvStatement implements IteratorAggregate, Statement
if ($params) { if ($params) {
$hasZeroIndex = array_key_exists(0, $params); $hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) { foreach ($params as $key => $val) {
$key = ($hasZeroIndex && is_numeric($key)) ? $key + 1 : $key; $key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key;
$this->bindValue($key, $val); $this->bindValue($key, $val);
} }
} }
if ( ! $this->stmt) { if (! $this->stmt) {
$this->stmt = $this->prepare(); $this->stmt = $this->prepare();
} }
if (!sqlsrv_execute($this->stmt)) { if (! sqlsrv_execute($this->stmt)) {
throw SQLSrvException::fromSqlSrvErrors(); throw SQLSrvException::fromSqlSrvErrors();
} }
...@@ -260,6 +258,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -260,6 +258,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
* Prepares SQL Server statement resource * Prepares SQL Server statement resource
* *
* @return resource * @return resource
*
* @throws SQLSrvException * @throws SQLSrvException
*/ */
private function prepare() private function prepare()
...@@ -272,8 +271,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -272,8 +271,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$params[$column - 1] = [ $params[$column - 1] = [
&$variable, &$variable,
SQLSRV_PARAM_IN, SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), sqlsrv_phptype_stream(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_VARBINARY('max'), sqlsrv_sqltype_varbinary('max'),
]; ];
break; break;
...@@ -281,7 +280,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -281,7 +280,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$params[$column - 1] = [ $params[$column - 1] = [
&$variable, &$variable,
SQLSRV_PARAM_IN, SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), sqlsrv_phptype_string(SQLSRV_ENC_BINARY),
]; ];
break; break;
...@@ -293,7 +292,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -293,7 +292,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$stmt = sqlsrv_prepare($this->conn, $this->sql, $params); $stmt = sqlsrv_prepare($this->conn, $this->sql, $params);
if (!$stmt) { if (! $stmt) {
throw SQLSrvException::fromSqlSrvErrors(); throw SQLSrvException::fromSqlSrvErrors();
} }
...@@ -325,11 +324,11 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -325,11 +324,11 @@ class SQLSrvStatement implements IteratorAggregate, Statement
* *
* @throws SQLSrvException * @throws SQLSrvException
*/ */
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{ {
// do not try fetching from the statement if it's not expected to contain result // do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation // in order to prevent exceptional situation
if (!$this->result) { if (! $this->result) {
return false; return false;
} }
...@@ -395,7 +394,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -395,7 +394,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
{ {
$row = $this->fetch(FetchMode::NUMERIC); $row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) { if ($row === false) {
return false; return false;
} }
......
...@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Driver; ...@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Driver;
/** /**
* Contract for a connection that is able to provide information about the server it is connected to. * Contract for a connection that is able to provide information about the server it is connected to.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
interface ServerInfoAwareConnection interface ServerInfoAwareConnection
{ {
......
...@@ -10,10 +10,7 @@ use Doctrine\DBAL\ParameterType; ...@@ -10,10 +10,7 @@ use Doctrine\DBAL\ParameterType;
* *
* This resembles (a subset of) the PDOStatement interface. * This resembles (a subset of) the PDOStatement interface.
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0
*/ */
interface Statement extends ResultStatement interface Statement extends ResultStatement
{ {
...@@ -90,7 +87,6 @@ interface Statement extends ResultStatement ...@@ -90,7 +87,6 @@ interface Statement extends ResultStatement
* if any, of their associated parameter markers or pass an array of input-only * if any, of their associated parameter markers or pass an array of input-only
* parameter values. * parameter values.
* *
*
* @param array|null $params An array of values with as many elements as there are * @param array|null $params An array of values with as many elements as there are
* bound parameters in the SQL statement being executed. * bound parameters in the SQL statement being executed.
* *
......
...@@ -2,16 +2,13 @@ ...@@ -2,16 +2,13 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
class StatementIterator implements \IteratorAggregate use IteratorAggregate;
class StatementIterator implements IteratorAggregate
{ {
/** /** @var Statement */
* @var Statement
*/
private $statement; private $statement;
/**
* @param Statement $statement
*/
public function __construct(Statement $statement) public function __construct(Statement $statement)
{ {
$this->statement = $statement; $this->statement = $statement;
...@@ -22,7 +19,7 @@ class StatementIterator implements \IteratorAggregate ...@@ -22,7 +19,7 @@ class StatementIterator implements \IteratorAggregate
*/ */
public function getIterator() public function getIterator()
{ {
while (false !== ($result = $this->statement->fetch())) { while (($result = $this->statement->fetch()) !== false) {
yield $result; yield $result;
} }
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL; namespace Doctrine\DBAL;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use PDO;
use function array_keys; use function array_keys;
use function array_map; use function array_map;
use function array_merge; use function array_merge;
...@@ -18,9 +19,6 @@ use function substr; ...@@ -18,9 +19,6 @@ use function substr;
/** /**
* Factory for creating Doctrine\DBAL\Connection instances. * Factory for creating Doctrine\DBAL\Connection instances.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/ */
final class DriverManager final class DriverManager
{ {
...@@ -32,18 +30,18 @@ final class DriverManager ...@@ -32,18 +30,18 @@ final class DriverManager
* *
* @var array * @var array
*/ */
private static $_driverMap = [ private static $_driverMap = [
'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', 'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver',
'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver', 'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver',
'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver', 'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver',
'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver', 'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver',
'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver', 'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver',
'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver', 'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver',
'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver', 'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver',
'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver', 'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver',
'sqlanywhere' => 'Doctrine\DBAL\Driver\SQLAnywhere\Driver', 'sqlanywhere' => 'Doctrine\DBAL\Driver\SQLAnywhere\Driver',
'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver', 'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver',
]; ];
/** /**
...@@ -115,24 +113,22 @@ final class DriverManager ...@@ -115,24 +113,22 @@ final class DriverManager
* <b>driverClass</b>: * <b>driverClass</b>:
* The driver class to use. * The driver class to use.
* *
* @param array $params The parameters. * @param array $params The parameters.
* @param \Doctrine\DBAL\Configuration|null $config The configuration to use. * @param Configuration|null $config The configuration to use.
* @param \Doctrine\Common\EventManager|null $eventManager The event manager to use. * @param EventManager|null $eventManager The event manager to use.
* *
* @return \Doctrine\DBAL\Connection * @throws DBALException
*
* @throws \Doctrine\DBAL\DBALException
*/ */
public static function getConnection( public static function getConnection(
array $params, array $params,
Configuration $config = null, ?Configuration $config = null,
EventManager $eventManager = null): Connection ?EventManager $eventManager = null
{ ) : Connection {
// create default config and event manager, if not set // create default config and event manager, if not set
if ( ! $config) { if (! $config) {
$config = new Configuration(); $config = new Configuration();
} }
if ( ! $eventManager) { if (! $eventManager) {
$eventManager = new EventManager(); $eventManager = new EventManager();
} }
...@@ -161,11 +157,11 @@ final class DriverManager ...@@ -161,11 +157,11 @@ final class DriverManager
} }
// check for existing pdo object // check for existing pdo object
if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) { if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) {
throw DBALException::invalidPdoInstance(); throw DBALException::invalidPdoInstance();
} elseif (isset($params['pdo'])) { } elseif (isset($params['pdo'])) {
$params['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME); $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME);
} else { } else {
self::_checkParams($params); self::_checkParams($params);
} }
...@@ -176,11 +172,11 @@ final class DriverManager ...@@ -176,11 +172,11 @@ final class DriverManager
$wrapperClass = 'Doctrine\DBAL\Connection'; $wrapperClass = 'Doctrine\DBAL\Connection';
if (isset($params['wrapperClass'])) { if (isset($params['wrapperClass'])) {
if (is_subclass_of($params['wrapperClass'], $wrapperClass)) { if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) {
$wrapperClass = $params['wrapperClass'];
} else {
throw DBALException::invalidWrapperClass($params['wrapperClass']); throw DBALException::invalidWrapperClass($params['wrapperClass']);
} }
$wrapperClass = $params['wrapperClass'];
} }
return new $wrapperClass($params, $driver, $config, $eventManager); return new $wrapperClass($params, $driver, $config, $eventManager);
...@@ -191,7 +187,7 @@ final class DriverManager ...@@ -191,7 +187,7 @@ final class DriverManager
* *
* @return array * @return array
*/ */
public static function getAvailableDrivers(): array public static function getAvailableDrivers() : array
{ {
return array_keys(self::$_driverMap); return array_keys(self::$_driverMap);
} }
...@@ -201,16 +197,14 @@ final class DriverManager ...@@ -201,16 +197,14 @@ final class DriverManager
* *
* @param array $params The list of parameters. * @param array $params The list of parameters.
* *
* @return void * @throws DBALException
*
* @throws \Doctrine\DBAL\DBALException
*/ */
private static function _checkParams(array $params): void private static function _checkParams(array $params) : void
{ {
// check existence of mandatory parameters // check existence of mandatory parameters
// driver // driver
if ( ! isset($params['driver']) && ! isset($params['driverClass'])) { if (! isset($params['driver']) && ! isset($params['driverClass'])) {
throw DBALException::driverRequired(); throw DBALException::driverRequired();
} }
...@@ -229,11 +223,9 @@ final class DriverManager ...@@ -229,11 +223,9 @@ final class DriverManager
/** /**
* Normalizes the given connection URL path. * Normalizes the given connection URL path.
* *
* @param string $urlPath
*
* @return string The normalized connection URL path * @return string The normalized connection URL path
*/ */
private static function normalizeDatabaseUrlPath(string $urlPath): string private static function normalizeDatabaseUrlPath(string $urlPath) : string
{ {
// Trim leading slash from URL path. // Trim leading slash from URL path.
return substr($urlPath, 1); return substr($urlPath, 1);
...@@ -250,9 +242,9 @@ final class DriverManager ...@@ -250,9 +242,9 @@ final class DriverManager
* *
* @throws DBALException * @throws DBALException
*/ */
private static function parseDatabaseUrl(array $params): array private static function parseDatabaseUrl(array $params) : array
{ {
if (!isset($params['url'])) { if (! isset($params['url'])) {
return $params; return $params;
} }
...@@ -297,14 +289,14 @@ final class DriverManager ...@@ -297,14 +289,14 @@ final class DriverManager
* Assumes that the connection URL scheme is already parsed and resolved into the given connection parameters * Assumes that the connection URL scheme is already parsed and resolved into the given connection parameters
* via {@link parseDatabaseUrlScheme}. * via {@link parseDatabaseUrlScheme}.
* *
* @see parseDatabaseUrlScheme
*
* @param array $url The URL parts to evaluate. * @param array $url The URL parts to evaluate.
* @param array $params The connection parameters to resolve. * @param array $params The connection parameters to resolve.
* *
* @return array The resolved connection parameters. * @return array The resolved connection parameters.
*
* @see parseDatabaseUrlScheme
*/ */
private static function parseDatabaseUrlPath(array $url, array $params): array private static function parseDatabaseUrlPath(array $url, array $params) : array
{ {
if (! isset($url['path'])) { if (! isset($url['path'])) {
return $params; return $params;
...@@ -333,7 +325,7 @@ final class DriverManager ...@@ -333,7 +325,7 @@ final class DriverManager
* *
* @return array The resolved connection parameters. * @return array The resolved connection parameters.
*/ */
private static function parseDatabaseUrlQuery(array $url, array $params): array private static function parseDatabaseUrlQuery(array $url, array $params) : array
{ {
if (! isset($url['query'])) { if (! isset($url['query'])) {
return $params; return $params;
...@@ -351,14 +343,14 @@ final class DriverManager ...@@ -351,14 +343,14 @@ final class DriverManager
* *
* Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}. * Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}.
* *
* @see normalizeDatabaseUrlPath
*
* @param array $url The regular connection URL parts to evaluate. * @param array $url The regular connection URL parts to evaluate.
* @param array $params The connection parameters to resolve. * @param array $params The connection parameters to resolve.
* *
* @return array The resolved connection parameters. * @return array The resolved connection parameters.
*
* @see normalizeDatabaseUrlPath
*/ */
private static function parseRegularDatabaseUrlPath(array $url, array $params): array private static function parseRegularDatabaseUrlPath(array $url, array $params) : array
{ {
$params['dbname'] = $url['path']; $params['dbname'] = $url['path'];
...@@ -370,14 +362,14 @@ final class DriverManager ...@@ -370,14 +362,14 @@ final class DriverManager
* *
* Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}. * Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}.
* *
* @see normalizeDatabaseUrlPath
*
* @param array $url The SQLite connection URL parts to evaluate. * @param array $url The SQLite connection URL parts to evaluate.
* @param array $params The connection parameters to resolve. * @param array $params The connection parameters to resolve.
* *
* @return array The resolved connection parameters. * @return array The resolved connection parameters.
*
* @see normalizeDatabaseUrlPath
*/ */
private static function parseSqliteDatabaseUrlPath(array $url, array $params): array private static function parseSqliteDatabaseUrlPath(array $url, array $params) : array
{ {
if ($url['path'] === ':memory:') { if ($url['path'] === ':memory:') {
$params['memory'] = true; $params['memory'] = true;
...@@ -400,7 +392,7 @@ final class DriverManager ...@@ -400,7 +392,7 @@ final class DriverManager
* *
* @throws DBALException if parsing failed or resolution is not possible. * @throws DBALException if parsing failed or resolution is not possible.
*/ */
private static function parseDatabaseUrlScheme(array $url, array $params): array private static function parseDatabaseUrlScheme(array $url, array $params) : array
{ {
if (isset($url['scheme'])) { if (isset($url['scheme'])) {
// The requested driver from the URL scheme takes precedence // The requested driver from the URL scheme takes precedence
......
...@@ -4,31 +4,27 @@ namespace Doctrine\DBAL\Event; ...@@ -4,31 +4,27 @@ namespace Doctrine\DBAL\Event;
use Doctrine\Common\EventArgs; use Doctrine\Common\EventArgs;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
/** /**
* Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection. * Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection.
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 1.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class ConnectionEventArgs extends EventArgs class ConnectionEventArgs extends EventArgs
{ {
/** /** @var Connection */
* @var \Doctrine\DBAL\Connection
*/
private $_connection; private $_connection;
/**
* @param \Doctrine\DBAL\Connection $connection
*/
public function __construct(Connection $connection) public function __construct(Connection $connection)
{ {
$this->_connection = $connection; $this->_connection = $connection;
} }
/** /**
* @return \Doctrine\DBAL\Connection * @return Connection
*/ */
public function getConnection() public function getConnection()
{ {
...@@ -36,7 +32,7 @@ class ConnectionEventArgs extends EventArgs ...@@ -36,7 +32,7 @@ class ConnectionEventArgs extends EventArgs
} }
/** /**
* @return \Doctrine\DBAL\Driver * @return Driver
*/ */
public function getDriver() public function getDriver()
{ {
...@@ -44,7 +40,7 @@ class ConnectionEventArgs extends EventArgs ...@@ -44,7 +40,7 @@ class ConnectionEventArgs extends EventArgs
} }
/** /**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform * @return AbstractPlatform
*/ */
public function getDatabasePlatform() public function getDatabasePlatform()
{ {
...@@ -52,7 +48,7 @@ class ConnectionEventArgs extends EventArgs ...@@ -52,7 +48,7 @@ class ConnectionEventArgs extends EventArgs
} }
/** /**
* @return \Doctrine\DBAL\Schema\AbstractSchemaManager * @return AbstractSchemaManager
*/ */
public function getSchemaManager() public function getSchemaManager()
{ {
......
...@@ -2,17 +2,16 @@ ...@@ -2,17 +2,16 @@
namespace Doctrine\DBAL\Event\Listeners; namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber;
/** /**
* MySQL Session Init Event Subscriber which allows to set the Client Encoding of the Connection. * MySQL Session Init Event Subscriber which allows to set the Client Encoding of the Connection.
* *
* @link www.doctrine-project.org
* @since 1.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @deprecated Use "charset" option to PDO MySQL Connection instead. * @deprecated Use "charset" option to PDO MySQL Connection instead.
*
* @link www.doctrine-project.org
*/ */
class MysqlSessionInit implements EventSubscriber class MysqlSessionInit implements EventSubscriber
{ {
...@@ -26,31 +25,29 @@ class MysqlSessionInit implements EventSubscriber ...@@ -26,31 +25,29 @@ class MysqlSessionInit implements EventSubscriber
/** /**
* The collation, or FALSE if no collation. * The collation, or FALSE if no collation.
* *
* @var string|boolean * @var string|bool
*/ */
private $_collation; private $_collation;
/** /**
* Configure Charset and Collation options of MySQL Client for each Connection. * Configure Charset and Collation options of MySQL Client for each Connection.
* *
* @param string $charset The charset. * @param string $charset The charset.
* @param string|boolean $collation The collation, or FALSE if no collation. * @param string|bool $collation The collation, or FALSE if no collation.
*/ */
public function __construct($charset = 'utf8', $collation = false) public function __construct($charset = 'utf8', $collation = false)
{ {
$this->_charset = $charset; $this->_charset = $charset;
$this->_collation = $collation; $this->_collation = $collation;
} }
/** /**
* @param \Doctrine\DBAL\Event\ConnectionEventArgs $args
*
* @return void * @return void
*/ */
public function postConnect(ConnectionEventArgs $args) public function postConnect(ConnectionEventArgs $args)
{ {
$collation = ($this->_collation) ? " COLLATE ".$this->_collation : ""; $collation = $this->_collation ? ' COLLATE ' . $this->_collation : '';
$args->getConnection()->executeUpdate("SET NAMES ".$this->_charset . $collation); $args->getConnection()->executeUpdate('SET NAMES ' . $this->_charset . $collation);
} }
/** /**
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
namespace Doctrine\DBAL\Event\Listeners; namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber; use const CASE_UPPER;
use function array_change_key_case; use function array_change_key_case;
use function array_merge; use function array_merge;
use function count; use function count;
...@@ -21,20 +22,16 @@ use function implode; ...@@ -21,20 +22,16 @@ use function implode;
* NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM" * NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM"
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class OracleSessionInit implements EventSubscriber class OracleSessionInit implements EventSubscriber
{ {
/** /** @var array */
* @var array
*/
protected $_defaultSessionVars = [ protected $_defaultSessionVars = [
'NLS_TIME_FORMAT' => "HH24:MI:SS", 'NLS_TIME_FORMAT' => 'HH24:MI:SS',
'NLS_DATE_FORMAT' => "YYYY-MM-DD HH24:MI:SS", 'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS',
'NLS_TIMESTAMP_FORMAT' => "YYYY-MM-DD HH24:MI:SS", 'NLS_TIMESTAMP_FORMAT' => 'YYYY-MM-DD HH24:MI:SS',
'NLS_TIMESTAMP_TZ_FORMAT' => "YYYY-MM-DD HH24:MI:SS TZH:TZM", 'NLS_TIMESTAMP_TZ_FORMAT' => 'YYYY-MM-DD HH24:MI:SS TZH:TZM',
'NLS_NUMERIC_CHARACTERS' => ".,", 'NLS_NUMERIC_CHARACTERS' => '.,',
]; ];
/** /**
...@@ -46,25 +43,25 @@ class OracleSessionInit implements EventSubscriber ...@@ -46,25 +43,25 @@ class OracleSessionInit implements EventSubscriber
} }
/** /**
* @param \Doctrine\DBAL\Event\ConnectionEventArgs $args
*
* @return void * @return void
*/ */
public function postConnect(ConnectionEventArgs $args) public function postConnect(ConnectionEventArgs $args)
{ {
if (count($this->_defaultSessionVars)) { if (! count($this->_defaultSessionVars)) {
array_change_key_case($this->_defaultSessionVars, \CASE_UPPER); return;
$vars = []; }
foreach ($this->_defaultSessionVars as $option => $value) {
if ($option === 'CURRENT_SCHEMA') { array_change_key_case($this->_defaultSessionVars, CASE_UPPER);
$vars[] = $option . " = " . $value; $vars = [];
} else { foreach ($this->_defaultSessionVars as $option => $value) {
$vars[] = $option . " = '" . $value . "'"; if ($option === 'CURRENT_SCHEMA') {
} $vars[] = $option . ' = ' . $value;
} else {
$vars[] = $option . " = '" . $value . "'";
} }
$sql = "ALTER SESSION SET ".implode(" ", $vars);
$args->getConnection()->executeUpdate($sql);
} }
$sql = 'ALTER SESSION SET ' . implode(' ', $vars);
$args->getConnection()->executeUpdate($sql);
} }
/** /**
......
...@@ -2,22 +2,18 @@ ...@@ -2,22 +2,18 @@
namespace Doctrine\DBAL\Event\Listeners; namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber;
/** /**
* Session init listener for executing a single SQL statement right after a connection is opened. * Session init listener for executing a single SQL statement right after a connection is opened.
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.2
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class SQLSessionInit implements EventSubscriber class SQLSessionInit implements EventSubscriber
{ {
/** /** @var string */
* @var string
*/
protected $sql; protected $sql;
/** /**
...@@ -29,8 +25,6 @@ class SQLSessionInit implements EventSubscriber ...@@ -29,8 +25,6 @@ class SQLSessionInit implements EventSubscriber
} }
/** /**
* @param \Doctrine\DBAL\Event\ConnectionEventArgs $args
*
* @return void * @return void
*/ */
public function postConnect(ConnectionEventArgs $args) public function postConnect(ConnectionEventArgs $args)
......
...@@ -11,30 +11,18 @@ use function is_array; ...@@ -11,30 +11,18 @@ use function is_array;
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform. * Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform.
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/ */
class SchemaAlterTableEventArgs extends SchemaEventArgs class SchemaAlterTableEventArgs extends SchemaEventArgs
{ {
/** /** @var TableDiff */
* @var \Doctrine\DBAL\Schema\TableDiff
*/
private $_tableDiff; private $_tableDiff;
/** /** @var AbstractPlatform */
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform; private $_platform;
/** /** @var array */
* @var array
*/
private $_sql = []; private $_sql = [];
/**
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(TableDiff $tableDiff, AbstractPlatform $platform) public function __construct(TableDiff $tableDiff, AbstractPlatform $platform)
{ {
$this->_tableDiff = $tableDiff; $this->_tableDiff = $tableDiff;
...@@ -42,7 +30,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs ...@@ -42,7 +30,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
} }
/** /**
* @return \Doctrine\DBAL\Schema\TableDiff * @return TableDiff
*/ */
public function getTableDiff() public function getTableDiff()
{ {
...@@ -50,7 +38,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs ...@@ -50,7 +38,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
} }
/** /**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform * @return AbstractPlatform
*/ */
public function getPlatform() public function getPlatform()
{ {
......
This diff is collapsed.
This diff is collapsed.
...@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Exception; ...@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Exception;
/** /**
* Base class for all connection related errors detected in the driver. * Base class for all connection related errors detected in the driver.
* *
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.5
*/ */
class ConnectionException extends DriverException class ConnectionException extends DriverException
{ {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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