secret
Created

  • Download Gist
AbstractPlatform.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php
abstract class AbstractPlatform
{
//...
 
/**
* Throw a more specific exception based on a SQL error code.
*
* @param \PDOException $e
* @throws \Doctrine\DBAL\DBALException
* @return void
*/
public function throwException(\PDOException $e)
{
$error_class = substr((string)$e->getCode(), 0, 2);
 
switch ($error_class) {
// Connection Exception
case '08':
// pass, connection exceptions seem to be handled elsewhere?
break;
case '0A':
case '0a':
$exception = 'FeatureNotSupportedException';
break;
case '21':
$exception = 'CardinalityViolationException';
break;
case '22':
$exception = 'DataException';
break;
case '23':
$exception = 'IntegrityConstraintException';
break;
case '24':
$exception = 'InvalidCursorStateException';
break;
case '25':
$exception = 'InvalidTransationStateException';
break;
// ... how many of these do the drivers actual use?
}
 
if (isset($exception)) {
$exception = 'Doctrine\\DBAL\\Exception\\' . $exception;
 
throw new $exception($e->getMessage(), 0, $e);
}
 
// if all else fails, just throw a DBALException
throw new DBALException($e->getMessage(), 0, $e);
}
 
// ...
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.