getMessage(); return static::wrapException($driver, $driverEx, $msg); } /** * @return self */ public static function driverException(Driver $driver, Throwable $driverEx) { return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage()); } /** * @return self */ private static function wrapException(Driver $driver, Throwable $driverEx, $msg) { if ($driverEx instanceof DriverException) { return $driverEx; } if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverExceptionInterface) { return $driver->convertException($msg, $driverEx); } return new self($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 \Doctrine\DBAL\DBALException */ public static function invalidWrapperClass($wrapperClass) { return new self("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' . 'subtype of \Doctrine\DBAL\Connection.'); } /** * @param string $driverClass * * @return \Doctrine\DBAL\DBALException */ public static function invalidDriverClass($driverClass) { return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.'); } /** * @param string $tableName * * @return \Doctrine\DBAL\DBALException */ public static function invalidTableName($tableName) { return new self('Invalid table name specified: ' . $tableName); } /** * @param string $tableName * * @return \Doctrine\DBAL\DBALException */ public static function noColumnsSpecifiedForTable($tableName) { return new self('No columns specified for table ' . $tableName); } /** * @return \Doctrine\DBAL\DBALException */ public static function limitOffsetInvalid() { return new self('Invalid Offset in Limit Query, it has to be larger than or equal to 0.'); } /** * @param string $name * * @return \Doctrine\DBAL\DBALException */ public static function typeExists($name) { return new self('Type ' . $name . ' already exists.'); } /** * @param string $name * * @return \Doctrine\DBAL\DBALException */ public static function unknownColumnType($name) { return new self('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 \Doctrine\DBAL\DBALException */ public static function typeNotFound($name) { return new self('Type to be overwritten ' . $name . ' does not exist.'); } public static function typeNotRegistered(Type $type) : self { return new self(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 self( sprintf('Type of the class %s@%s is already registered.', get_class($type), spl_object_hash($type)) ); } }