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

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