Commit cd8e768c authored by Benjamin Eberlei's avatar Benjamin Eberlei

Enhance error reporting in date related types when a ConversionException is thrown

parent 58b03f35
......@@ -45,4 +45,18 @@ class ConversionException extends \Doctrine\DBAL\DBALException
$value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value;
return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType);
}
/**
* Thrown when a Database to Doctrine Type Conversion fails and we can make a statement
* about the expected format.
*
* @param string $value
* @param string $toType
* @return ConversionException
*/
static public function conversionFailedFormat($value, $toType, $expectedFormat)
{
$value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value;
return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType);
}
}
\ No newline at end of file
......@@ -52,7 +52,7 @@ class DateTimeType extends Type
$val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
}
return $val;
}
......
......@@ -72,7 +72,7 @@ class DateTimeTzType extends Type
$val = \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeTzFormatString());
}
return $val;
}
......
......@@ -52,7 +52,7 @@ class DateType extends Type
$val = \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString());
}
return $val;
}
......
......@@ -61,7 +61,7 @@ class TimeType extends Type
$val = \DateTime::createFromFormat($platform->getTimeFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString());
}
return $val;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment