getMessage(); return self::wrapException($driver, $driverEx, $msg); } /** * @deprecated * * @return Exception */ public static function driverException(Driver $driver, Throwable $driverEx) { return self::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage()); } /** * @return Exception */ private static function wrapException(Driver $driver, Throwable $driverEx, string $msg) { if ($driverEx instanceof DriverException) { return $driverEx; } if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DeprecatedDriverException) { return $driver->convertException($msg, $driverEx); } return new Exception($msg, 0, $driverEx); } /** * Returns a human-readable representation of an array of parameters. * This properly handles binary data by returning a hex representation. * * @param mixed[] $params * * @return string */ private static function formatParameters(array $params) { return '[' . implode(', ', array_map(static function ($param) { if (is_resource($param)) { return (string) $param; } $json = @json_encode($param); if (! is_string($json) || $json === 'null' && is_string($param)) { // JSON encoding failed, this is not a UTF-8 string. return sprintf('"%s"', preg_replace('/.{2}/', '\\x$0', bin2hex($param))); } return $json; }, $params)) . ']'; } /** * @param string $wrapperClass * * @return Exception */ public static function invalidWrapperClass($wrapperClass) { return new Exception("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' . 'subtype of \Doctrine\DBAL\Connection.'); } /** * @param string $driverClass * * @return Exception */ public static function invalidDriverClass($driverClass) { return new Exception( "The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.' ); } /** * @param string $tableName * * @return Exception */ public static function invalidTableName($tableName) { return new Exception('Invalid table name specified: ' . $tableName); } /** * @param string $tableName * * @return Exception */ public static function noColumnsSpecifiedForTable($tableName) { return new Exception('No columns specified for table ' . $tableName); } /** * @return Exception */ public static function limitOffsetInvalid() { return new Exception('Invalid Offset in Limit Query, it has to be larger than or equal to 0.'); } /** * @param string $name * * @return Exception */ public static function typeExists($name) { return new Exception('Type ' . $name . ' already exists.'); } /** * @param string $name * * @return Exception */ public static function unknownColumnType($name) { 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 ' . 'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' . 'Type#getMappedDatabaseTypes(). If the type name is empty you might ' . 'have a problem with the cache or forgot some mapping information.'); } /** * @param string $name * * @return Exception */ public static function typeNotFound($name) { 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)) ); } }