vendor/doctrine/dbal/src/Exception.php line 18

Open in your IDE?
  1. <?php
  2. namespace Doctrine\DBAL;
  3. use Doctrine\DBAL\Platforms\AbstractPlatform;
  4. use Doctrine\DBAL\Types\Type;
  5. use function get_class;
  6. use function gettype;
  7. use function implode;
  8. use function is_object;
  9. use function spl_object_hash;
  10. use function sprintf;
  11. /**
  12.  * @psalm-immutable
  13.  */
  14. class Exception extends \Exception
  15. {
  16.     public static function notSupported(string $method): self
  17.     {
  18.         return new self(sprintf("Operation '%s' is not supported by platform."$method));
  19.     }
  20.     /**
  21.      * @param mixed $invalidPlatform
  22.      */
  23.     public static function invalidPlatformType($invalidPlatform): self
  24.     {
  25.         if (is_object($invalidPlatform)) {
  26.             return new self(
  27.                 sprintf(
  28.                     "Option 'platform' must be a subtype of '%s', instance of '%s' given",
  29.                     AbstractPlatform::class,
  30.                     get_class($invalidPlatform)
  31.                 )
  32.             );
  33.         }
  34.         return new self(
  35.             sprintf(
  36.                 "Option 'platform' must be an object and subtype of '%s'. Got '%s'",
  37.                 AbstractPlatform::class,
  38.                 gettype($invalidPlatform)
  39.             )
  40.         );
  41.     }
  42.     /**
  43.      * Returns a new instance for an invalid specified platform version.
  44.      *
  45.      * @param string $version        The invalid platform version given.
  46.      * @param string $expectedFormat The expected platform version format.
  47.      */
  48.     public static function invalidPlatformVersionSpecified(string $versionstring $expectedFormat): self
  49.     {
  50.         return new self(
  51.             sprintf(
  52.                 'Invalid platform version "%s" specified. ' .
  53.                 'The platform version has to be specified in the format: "%s".',
  54.                 $version,
  55.                 $expectedFormat
  56.             )
  57.         );
  58.     }
  59.     /**
  60.      * @param string|null $url The URL that was provided in the connection parameters (if any).
  61.      */
  62.     public static function driverRequired(?string $url null): self
  63.     {
  64.         if ($url !== null) {
  65.             return new self(
  66.                 sprintf(
  67.                     "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " .
  68.                     'is given to DriverManager::getConnection(). Given URL: %s',
  69.                     $url
  70.                 )
  71.             );
  72.         }
  73.         return new self("The options 'driver' or 'driverClass' are mandatory if no PDO " .
  74.             'instance is given to DriverManager::getConnection().');
  75.     }
  76.     /**
  77.      * @param string[] $knownDrivers
  78.      */
  79.     public static function unknownDriver(string $unknownDriverName, array $knownDrivers): self
  80.     {
  81.         return new self("The given 'driver' " $unknownDriverName ' is unknown, ' .
  82.             'Doctrine currently supports only the following drivers: ' implode(', '$knownDrivers));
  83.     }
  84.     public static function invalidWrapperClass(string $wrapperClass): self
  85.     {
  86.         return new self("The given 'wrapperClass' " $wrapperClass ' has to be a ' .
  87.             'subtype of \Doctrine\DBAL\Connection.');
  88.     }
  89.     public static function invalidDriverClass(string $driverClass): self
  90.     {
  91.         return new self(
  92.             "The given 'driverClass' " $driverClass ' has to implement the ' Driver::class . ' interface.'
  93.         );
  94.     }
  95.     public static function noColumnsSpecifiedForTable(string $tableName): self
  96.     {
  97.         return new self('No columns specified for table ' $tableName);
  98.     }
  99.     public static function typeExists(string $name): self
  100.     {
  101.         return new self('Type ' $name ' already exists.');
  102.     }
  103.     public static function unknownColumnType(string $name): self
  104.     {
  105.         return new self('Unknown column type "' $name '" requested. Any Doctrine type that you use has ' .
  106.             'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' .
  107.             'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' .
  108.             'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' .
  109.             'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' .
  110.             'Type#getMappedDatabaseTypes(). If the type name is empty you might ' .
  111.             'have a problem with the cache or forgot some mapping information.');
  112.     }
  113.     public static function typeNotFound(string $name): self
  114.     {
  115.         return new self('Type to be overwritten ' $name ' does not exist.');
  116.     }
  117.     public static function typeNotRegistered(Type $type): self
  118.     {
  119.         return new self(
  120.             sprintf('Type of the class %s@%s is not registered.'get_class($type), spl_object_hash($type))
  121.         );
  122.     }
  123.     public static function typeAlreadyRegistered(Type $type): self
  124.     {
  125.         return new self(
  126.             sprintf('Type of the class %s@%s is already registered.'get_class($type), spl_object_hash($type))
  127.         );
  128.     }
  129. }