composer update
This commit is contained in:
@@ -1,25 +1,20 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySQLDriver;
|
||||
use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
|
||||
use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver;
|
||||
use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver;
|
||||
use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver;
|
||||
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOCIDriver;
|
||||
use Doctrine\DBAL\Driver\PDOPgSql\Driver as PDOPgSQLDriver;
|
||||
use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSQLiteDriver;
|
||||
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver;
|
||||
use Doctrine\DBAL\Driver\SQLAnywhere\Driver as SQLAnywhereDriver;
|
||||
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver;
|
||||
use PDO;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
@@ -35,9 +30,6 @@ use function substr;
|
||||
|
||||
/**
|
||||
* Factory for creating Doctrine\DBAL\Connection instances.
|
||||
*
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @since 2.0
|
||||
*/
|
||||
final class DriverManager
|
||||
{
|
||||
@@ -47,24 +39,26 @@ final class DriverManager
|
||||
* To add your own driver use the 'driverClass' parameter to
|
||||
* {@link DriverManager::getConnection()}.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
private static $_driverMap = [
|
||||
'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
|
||||
'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver',
|
||||
'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver',
|
||||
'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver',
|
||||
'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver',
|
||||
'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver',
|
||||
'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver',
|
||||
'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver',
|
||||
'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver',
|
||||
'sqlanywhere' => 'Doctrine\DBAL\Driver\SQLAnywhere\Driver',
|
||||
'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver',
|
||||
private static $_driverMap = [
|
||||
'pdo_mysql' => PDOMySQLDriver::class,
|
||||
'pdo_sqlite' => PDOSQLiteDriver::class,
|
||||
'pdo_pgsql' => PDOPgSQLDriver::class,
|
||||
'pdo_oci' => PDOOCIDriver::class,
|
||||
'oci8' => OCI8Driver::class,
|
||||
'ibm_db2' => DB2Driver::class,
|
||||
'pdo_sqlsrv' => PDOSQLSrvDriver::class,
|
||||
'mysqli' => MySQLiDriver::class,
|
||||
'drizzle_pdo_mysql' => DrizzlePDOMySQLDriver::class,
|
||||
'sqlanywhere' => SQLAnywhereDriver::class,
|
||||
'sqlsrv' => SQLSrvDriver::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* List of URL schemes from a database URL and their mappings to driver.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private static $driverSchemeAliases = [
|
||||
'db2' => 'ibm_db2',
|
||||
@@ -132,35 +126,55 @@ final class DriverManager
|
||||
* <b>driverClass</b>:
|
||||
* The driver class to use.
|
||||
*
|
||||
* @param array $params The parameters.
|
||||
* @param \Doctrine\DBAL\Configuration|null $config The configuration to use.
|
||||
* @param \Doctrine\Common\EventManager|null $eventManager The event manager to use.
|
||||
* @param mixed[] $params The parameters.
|
||||
* @param Configuration|null $config The configuration to use.
|
||||
* @param EventManager|null $eventManager The event manager to use.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Connection
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public static function getConnection(
|
||||
array $params,
|
||||
Configuration $config = null,
|
||||
EventManager $eventManager = null): Connection
|
||||
{
|
||||
array $params,
|
||||
?Configuration $config = null,
|
||||
?EventManager $eventManager = null
|
||||
) : Connection {
|
||||
// create default config and event manager, if not set
|
||||
if ( ! $config) {
|
||||
if (! $config) {
|
||||
$config = new Configuration();
|
||||
}
|
||||
if ( ! $eventManager) {
|
||||
if (! $eventManager) {
|
||||
$eventManager = new EventManager();
|
||||
}
|
||||
|
||||
$params = self::parseDatabaseUrl($params);
|
||||
|
||||
// URL support for MasterSlaveConnection
|
||||
if (isset($params['master'])) {
|
||||
$params['master'] = self::parseDatabaseUrl($params['master']);
|
||||
}
|
||||
|
||||
if (isset($params['slaves'])) {
|
||||
foreach ($params['slaves'] as $key => $slaveParams) {
|
||||
$params['slaves'][$key] = self::parseDatabaseUrl($slaveParams);
|
||||
}
|
||||
}
|
||||
|
||||
// URL support for PoolingShardConnection
|
||||
if (isset($params['global'])) {
|
||||
$params['global'] = self::parseDatabaseUrl($params['global']);
|
||||
}
|
||||
|
||||
if (isset($params['shards'])) {
|
||||
foreach ($params['shards'] as $key => $shardParams) {
|
||||
$params['shards'][$key] = self::parseDatabaseUrl($shardParams);
|
||||
}
|
||||
}
|
||||
|
||||
// check for existing pdo object
|
||||
if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) {
|
||||
if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) {
|
||||
throw DBALException::invalidPdoInstance();
|
||||
} elseif (isset($params['pdo'])) {
|
||||
$params['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||
$params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
} else {
|
||||
self::_checkParams($params);
|
||||
}
|
||||
@@ -169,13 +183,13 @@ final class DriverManager
|
||||
|
||||
$driver = new $className();
|
||||
|
||||
$wrapperClass = 'Doctrine\DBAL\Connection';
|
||||
$wrapperClass = Connection::class;
|
||||
if (isset($params['wrapperClass'])) {
|
||||
if (is_subclass_of($params['wrapperClass'], $wrapperClass)) {
|
||||
$wrapperClass = $params['wrapperClass'];
|
||||
} else {
|
||||
if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) {
|
||||
throw DBALException::invalidWrapperClass($params['wrapperClass']);
|
||||
}
|
||||
|
||||
$wrapperClass = $params['wrapperClass'];
|
||||
}
|
||||
|
||||
return new $wrapperClass($params, $driver, $config, $eventManager);
|
||||
@@ -184,9 +198,9 @@ final class DriverManager
|
||||
/**
|
||||
* Returns the list of supported drivers.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getAvailableDrivers(): array
|
||||
public static function getAvailableDrivers() : array
|
||||
{
|
||||
return array_keys(self::$_driverMap);
|
||||
}
|
||||
@@ -194,18 +208,16 @@ final class DriverManager
|
||||
/**
|
||||
* Checks the list of parameters.
|
||||
*
|
||||
* @param array $params The list of parameters.
|
||||
* @param mixed[] $params The list of parameters.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
* @throws DBALException
|
||||
*/
|
||||
private static function _checkParams(array $params): void
|
||||
private static function _checkParams(array $params) : void
|
||||
{
|
||||
// check existence of mandatory parameters
|
||||
|
||||
// driver
|
||||
if ( ! isset($params['driver']) && ! isset($params['driverClass'])) {
|
||||
if (! isset($params['driver']) && ! isset($params['driverClass'])) {
|
||||
throw DBALException::driverRequired();
|
||||
}
|
||||
|
||||
@@ -216,7 +228,7 @@ final class DriverManager
|
||||
throw DBALException::unknownDriver($params['driver'], array_keys(self::$_driverMap));
|
||||
}
|
||||
|
||||
if (isset($params['driverClass']) && ! in_array('Doctrine\DBAL\Driver', class_implements($params['driverClass'], true))) {
|
||||
if (isset($params['driverClass']) && ! in_array(Driver::class, class_implements($params['driverClass'], true))) {
|
||||
throw DBALException::invalidDriverClass($params['driverClass']);
|
||||
}
|
||||
}
|
||||
@@ -224,11 +236,9 @@ final class DriverManager
|
||||
/**
|
||||
* Normalizes the given connection URL path.
|
||||
*
|
||||
* @param string $urlPath
|
||||
*
|
||||
* @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.
|
||||
return substr($urlPath, 1);
|
||||
@@ -238,16 +248,16 @@ final class DriverManager
|
||||
* Extracts parts from a database URL, if present, and returns an
|
||||
* updated list of parameters.
|
||||
*
|
||||
* @param array $params The list of parameters.
|
||||
* @param mixed[] $params The list of parameters.
|
||||
*
|
||||
* @return array A modified list of parameters with info from a database
|
||||
* URL extracted into indidivual parameter parts.
|
||||
* @return mixed[] A modified list of parameters with info from a database
|
||||
* URL extracted into indidivual parameter parts.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -292,14 +302,14 @@ final class DriverManager
|
||||
* Assumes that the connection URL scheme is already parsed and resolved into the given connection parameters
|
||||
* via {@link parseDatabaseUrlScheme}.
|
||||
*
|
||||
* @param array $url The URL parts to evaluate.
|
||||
* @param array $params The connection parameters to resolve.
|
||||
*
|
||||
* @return array The resolved connection parameters.
|
||||
*
|
||||
* @see parseDatabaseUrlScheme
|
||||
*
|
||||
* @param mixed[] $url The URL parts to evaluate.
|
||||
* @param mixed[] $params The connection parameters to resolve.
|
||||
*
|
||||
* @return mixed[] The resolved connection parameters.
|
||||
*/
|
||||
private static function parseDatabaseUrlPath(array $url, array $params): array
|
||||
private static function parseDatabaseUrlPath(array $url, array $params) : array
|
||||
{
|
||||
if (! isset($url['path'])) {
|
||||
return $params;
|
||||
@@ -323,12 +333,12 @@ final class DriverManager
|
||||
/**
|
||||
* Parses the query part of the given connection URL and resolves the given connection parameters.
|
||||
*
|
||||
* @param array $url The connection URL parts to evaluate.
|
||||
* @param array $params The connection parameters to resolve.
|
||||
* @param mixed[] $url The connection URL parts to evaluate.
|
||||
* @param mixed[] $params The connection parameters to resolve.
|
||||
*
|
||||
* @return array The resolved connection parameters.
|
||||
* @return mixed[] 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'])) {
|
||||
return $params;
|
||||
@@ -346,14 +356,14 @@ final class DriverManager
|
||||
*
|
||||
* Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}.
|
||||
*
|
||||
* @param array $url The regular connection URL parts to evaluate.
|
||||
* @param array $params The connection parameters to resolve.
|
||||
*
|
||||
* @return array The resolved connection parameters.
|
||||
*
|
||||
* @see normalizeDatabaseUrlPath
|
||||
*
|
||||
* @param mixed[] $url The regular connection URL parts to evaluate.
|
||||
* @param mixed[] $params The connection parameters to resolve.
|
||||
*
|
||||
* @return mixed[] The resolved connection parameters.
|
||||
*/
|
||||
private static function parseRegularDatabaseUrlPath(array $url, array $params): array
|
||||
private static function parseRegularDatabaseUrlPath(array $url, array $params) : array
|
||||
{
|
||||
$params['dbname'] = $url['path'];
|
||||
|
||||
@@ -365,14 +375,14 @@ final class DriverManager
|
||||
*
|
||||
* Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}.
|
||||
*
|
||||
* @param array $url The SQLite connection URL parts to evaluate.
|
||||
* @param array $params The connection parameters to resolve.
|
||||
*
|
||||
* @return array The resolved connection parameters.
|
||||
*
|
||||
* @see normalizeDatabaseUrlPath
|
||||
*
|
||||
* @param mixed[] $url The SQLite connection URL parts to evaluate.
|
||||
* @param mixed[] $params The connection parameters to resolve.
|
||||
*
|
||||
* @return mixed[] The resolved connection parameters.
|
||||
*/
|
||||
private static function parseSqliteDatabaseUrlPath(array $url, array $params): array
|
||||
private static function parseSqliteDatabaseUrlPath(array $url, array $params) : array
|
||||
{
|
||||
if ($url['path'] === ':memory:') {
|
||||
$params['memory'] = true;
|
||||
@@ -388,14 +398,14 @@ final class DriverManager
|
||||
/**
|
||||
* Parses the scheme part from given connection URL and resolves the given connection parameters.
|
||||
*
|
||||
* @param array $url The connection URL parts to evaluate.
|
||||
* @param array $params The connection parameters to resolve.
|
||||
* @param mixed[] $url The connection URL parts to evaluate.
|
||||
* @param mixed[] $params The connection parameters to resolve.
|
||||
*
|
||||
* @return array The resolved connection parameters.
|
||||
* @return mixed[] The resolved connection parameters.
|
||||
*
|
||||
* @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'])) {
|
||||
// The requested driver from the URL scheme takes precedence
|
||||
|
Reference in New Issue
Block a user