updated-packages
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
|
||||
namespace Doctrine\DBAL;
|
||||
|
||||
use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface;
|
||||
use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException;
|
||||
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
|
||||
use Doctrine\DBAL\Exception\DriverException;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Exception;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Throwable;
|
||||
|
||||
use function array_map;
|
||||
use function bin2hex;
|
||||
use function get_class;
|
||||
@@ -17,24 +18,33 @@ use function is_object;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
use function json_encode;
|
||||
use function preg_replace;
|
||||
use function spl_object_hash;
|
||||
use function sprintf;
|
||||
use function str_split;
|
||||
|
||||
class DBALException extends Exception
|
||||
/**
|
||||
* @deprecated Use {@link Exception} instead
|
||||
*
|
||||
* @psalm-immutable
|
||||
*/
|
||||
class DBALException extends \Exception
|
||||
{
|
||||
/**
|
||||
* @param string $method
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function notSupported($method)
|
||||
{
|
||||
return new self(sprintf("Operation '%s' is not supported by platform.", $method));
|
||||
return new Exception(sprintf("Operation '%s' is not supported by platform.", $method));
|
||||
}
|
||||
|
||||
public static function invalidPlatformSpecified() : self
|
||||
/**
|
||||
* @deprecated Use {@link invalidPlatformType()} instead.
|
||||
*/
|
||||
public static function invalidPlatformSpecified(): self
|
||||
{
|
||||
return new self(
|
||||
return new Exception(
|
||||
"Invalid 'platform' option specified, need to give an instance of " . AbstractPlatform::class . '.'
|
||||
);
|
||||
}
|
||||
@@ -42,10 +52,10 @@ class DBALException extends Exception
|
||||
/**
|
||||
* @param mixed $invalidPlatform
|
||||
*/
|
||||
public static function invalidPlatformType($invalidPlatform) : self
|
||||
public static function invalidPlatformType($invalidPlatform): self
|
||||
{
|
||||
if (is_object($invalidPlatform)) {
|
||||
return new self(
|
||||
return new Exception(
|
||||
sprintf(
|
||||
"Option 'platform' must be a subtype of '%s', instance of '%s' given",
|
||||
AbstractPlatform::class,
|
||||
@@ -54,7 +64,7 @@ class DBALException extends Exception
|
||||
);
|
||||
}
|
||||
|
||||
return new self(
|
||||
return new Exception(
|
||||
sprintf(
|
||||
"Option 'platform' must be an object and subtype of '%s'. Got '%s'",
|
||||
AbstractPlatform::class,
|
||||
@@ -69,11 +79,11 @@ class DBALException extends Exception
|
||||
* @param string $version The invalid platform version given.
|
||||
* @param string $expectedFormat The expected platform version format.
|
||||
*
|
||||
* @return DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function invalidPlatformVersionSpecified($version, $expectedFormat)
|
||||
{
|
||||
return new self(
|
||||
return new Exception(
|
||||
sprintf(
|
||||
'Invalid platform version "%s" specified. ' .
|
||||
'The platform version has to be specified in the format: "%s".',
|
||||
@@ -84,11 +94,13 @@ class DBALException extends Exception
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @deprecated Passing a PDO instance in connection parameters is deprecated.
|
||||
*
|
||||
* @return Exception
|
||||
*/
|
||||
public static function invalidPdoInstance()
|
||||
{
|
||||
return new self(
|
||||
return new Exception(
|
||||
"The 'pdo' option was used in DriverManager::getConnection() but no " .
|
||||
'instance of PDO was given.'
|
||||
);
|
||||
@@ -97,12 +109,12 @@ class DBALException extends Exception
|
||||
/**
|
||||
* @param string|null $url The URL that was provided in the connection parameters (if any).
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function driverRequired($url = null)
|
||||
{
|
||||
if ($url) {
|
||||
return new self(
|
||||
return new Exception(
|
||||
sprintf(
|
||||
"The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " .
|
||||
'is given to DriverManager::getConnection(). Given URL: %s',
|
||||
@@ -111,7 +123,7 @@ class DBALException extends Exception
|
||||
);
|
||||
}
|
||||
|
||||
return new self("The options 'driver' or 'driverClass' are mandatory if no PDO " .
|
||||
return new Exception("The options 'driver' or 'driverClass' are mandatory if no PDO " .
|
||||
'instance is given to DriverManager::getConnection().');
|
||||
}
|
||||
|
||||
@@ -119,20 +131,21 @@ class DBALException extends Exception
|
||||
* @param string $unknownDriverName
|
||||
* @param string[] $knownDrivers
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function unknownDriver($unknownDriverName, array $knownDrivers)
|
||||
{
|
||||
return new self("The given 'driver' " . $unknownDriverName . ' is unknown, ' .
|
||||
return new Exception("The given 'driver' " . $unknownDriverName . ' is unknown, ' .
|
||||
'Doctrine currently supports only the following drivers: ' . implode(', ', $knownDrivers));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Exception $driverEx
|
||||
* @param string $sql
|
||||
* @param mixed[] $params
|
||||
* @deprecated
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @param string $sql
|
||||
* @param mixed[] $params
|
||||
*
|
||||
* @return Exception
|
||||
*/
|
||||
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
|
||||
{
|
||||
@@ -140,36 +153,36 @@ class DBALException extends Exception
|
||||
if ($params) {
|
||||
$msg .= ' with params ' . self::formatParameters($params);
|
||||
}
|
||||
|
||||
$msg .= ":\n\n" . $driverEx->getMessage();
|
||||
|
||||
return static::wrapException($driver, $driverEx, $msg);
|
||||
return self::wrapException($driver, $driverEx, $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Exception $driverEx
|
||||
* @deprecated
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function driverException(Driver $driver, Throwable $driverEx)
|
||||
{
|
||||
return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
|
||||
return self::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Exception $driverEx
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
private static function wrapException(Driver $driver, Throwable $driverEx, $msg)
|
||||
private static function wrapException(Driver $driver, Throwable $driverEx, string $msg)
|
||||
{
|
||||
if ($driverEx instanceof DriverException) {
|
||||
return $driverEx;
|
||||
}
|
||||
if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverExceptionInterface) {
|
||||
|
||||
if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DeprecatedDriverException) {
|
||||
return $driver->convertException($msg, $driverEx);
|
||||
}
|
||||
|
||||
return new self($msg, 0, $driverEx);
|
||||
return new Exception($msg, 0, $driverEx);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +204,7 @@ class DBALException extends Exception
|
||||
|
||||
if (! is_string($json) || $json === 'null' && is_string($param)) {
|
||||
// JSON encoding failed, this is not a UTF-8 string.
|
||||
return '"\x' . implode('\x', str_split(bin2hex($param), 2)) . '"';
|
||||
return sprintf('"%s"', preg_replace('/.{2}/', '\\x$0', bin2hex($param)));
|
||||
}
|
||||
|
||||
return $json;
|
||||
@@ -201,70 +214,72 @@ class DBALException extends Exception
|
||||
/**
|
||||
* @param string $wrapperClass
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function invalidWrapperClass($wrapperClass)
|
||||
{
|
||||
return new self("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' .
|
||||
return new Exception("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' .
|
||||
'subtype of \Doctrine\DBAL\Connection.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $driverClass
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function invalidDriverClass($driverClass)
|
||||
{
|
||||
return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.');
|
||||
return new Exception(
|
||||
"The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function invalidTableName($tableName)
|
||||
{
|
||||
return new self('Invalid table name specified: ' . $tableName);
|
||||
return new Exception('Invalid table name specified: ' . $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function noColumnsSpecifiedForTable($tableName)
|
||||
{
|
||||
return new self('No columns specified for table ' . $tableName);
|
||||
return new Exception('No columns specified for table ' . $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function limitOffsetInvalid()
|
||||
{
|
||||
return new self('Invalid Offset in Limit Query, it has to be larger than or equal to 0.');
|
||||
return new Exception('Invalid Offset in Limit Query, it has to be larger than or equal to 0.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function typeExists($name)
|
||||
{
|
||||
return new self('Type ' . $name . ' already exists.');
|
||||
return new Exception('Type ' . $name . ' already exists.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function unknownColumnType($name)
|
||||
{
|
||||
return new self('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' .
|
||||
return new Exception('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' .
|
||||
'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' .
|
||||
'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' .
|
||||
'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' .
|
||||
@@ -276,10 +291,24 @@ class DBALException extends Exception
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return \Doctrine\DBAL\DBALException
|
||||
* @return Exception
|
||||
*/
|
||||
public static function typeNotFound($name)
|
||||
{
|
||||
return new self('Type to be overwritten ' . $name . ' does not exist.');
|
||||
return new Exception('Type to be overwritten ' . $name . ' does not exist.');
|
||||
}
|
||||
|
||||
public static function typeNotRegistered(Type $type): self
|
||||
{
|
||||
return new Exception(
|
||||
sprintf('Type of the class %s@%s is not registered.', get_class($type), spl_object_hash($type))
|
||||
);
|
||||
}
|
||||
|
||||
public static function typeAlreadyRegistered(Type $type): self
|
||||
{
|
||||
return new Exception(
|
||||
sprintf('Type of the class %s@%s is already registered.', get_class($type), spl_object_hash($type))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user