Doctrine\DBAL\Types\ConversionException::conversionFailed PHP Метод

conversionFailed() публичный статический Метод

Thrown when a Database to Doctrine Type Conversion fails.
public static conversionFailed ( string $value, string $toType ) : ConversionException
$value string
$toType string
Результат ConversionException
    public static function conversionFailed($value, $toType)
    {
        $value = strlen($value) > 32 ? substr($value, 0, 20) . '...' : $value;
        return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType);
    }

Usage Example

Пример #1
0
 /**
  * (non-PHPdoc)
  *
  * @see \Doctrine\DBAL\Types\Type::convertToPHPValue()
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     $matches = array();
     preg_match('/(?:(?P<y>[0-9]+) (?:year|years))?' . ' ?(?:(?P<m>[0-9]+) (?:months|month|mons|mon))?' . ' ?(?:(?P<d>[0-9]+) (?:days|day))?' . ' ?(?:(?P<h>[0-9]{2}):(?P<i>[0-9]{2}):(?P<s>[0-9]{2}))?/i', $value, $matches);
     if (empty($matches)) {
         throw ConversionException::conversionFailed($value, self::NAME);
     }
     $interval = new Interval('PT0S');
     if (!empty($matches['y'])) {
         $interval->y = intval($matches['y']);
     }
     if (!empty($matches['m'])) {
         $interval->m = intval($matches['m']);
     }
     if (!empty($matches['d'])) {
         $interval->d = intval($matches['d']);
     }
     if (!empty($matches['h'])) {
         $interval->h = intval($matches['h']);
     }
     if (!empty($matches['i'])) {
         $interval->i = intval($matches['i']);
     }
     if (!empty($matches['s'])) {
         $interval->s = intval($matches['s']);
     }
     return $interval;
 }
All Usage Examples Of Doctrine\DBAL\Types\ConversionException::conversionFailed