本文整理汇总了PHP中Doctrine\DBAL\Types\ConversionException::conversionFailedFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP ConversionException::conversionFailedFormat方法的具体用法?PHP ConversionException::conversionFailedFormat怎么用?PHP ConversionException::conversionFailedFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Types\ConversionException
的用法示例。
在下文中一共展示了ConversionException::conversionFailedFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertToPHPValue
/**
* @see \Doctrine\DBAL\Types\JsonArrayType::convertToPHPValue()
* @param string $sValue
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $oPlatform
* @throws \Doctrine\DBAL\Types\ConversionException
* @return \Zend\Http\Headers
*/
public function convertToPHPValue($sValue, \Doctrine\DBAL\Platforms\AbstractPlatform $oPlatform)
{
$aValue = parent::convertToPHPValue($sValue, $oPlatform);
if (is_array($aValue)) {
$oHeaders = new \Zend\Http\Headers();
return $oHeaders->addHeaders($aValue);
}
throw \Doctrine\DBAL\Types\ConversionException::conversionFailedFormat($sValue, $this->getName(), 'json encoded array');
}
示例2: convertDateTimeString
/**
* @param string|DateTime $value
* @param string $fromFormat
* @param string $toFormat
*
* @return string
*
* @throws ConversionException
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
private function convertDateTimeString($value, $fromFormat, $toFormat)
{
$dateTime = $value instanceof DateTime ? $value : DateTime::createFromFormat($fromFormat, $value);
if ($dateTime === false) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $fromFormat);
}
$result = $dateTime->format($toFormat);
return $result;
}
示例3: convertToPHPValue
/**
* @override
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (null !== $value) {
if (1 !== preg_match('/^\\d+$/', $value)) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), '^\\d+$');
}
$value = DateInterval::fromSeconds($value);
}
return $value;
}
示例4: convertToPHPValue
/**
* @override
* @param mixed $value
* @param AbstractPlatform $platform
* @return mixed|DateRange
* @throws ConversionException
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (null !== $value) {
if (false == preg_match('/^(\\[|\\()(\\d{4})-(\\d{2})-(\\d{2}),(\\d{4})-(\\d{2})-(\\d{2})(\\]|\\))$/', $value)) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), '(\\[|\\()(\\d{4})-(\\d{2})-(\\d{2}),(\\d{4})-(\\d{2})-(\\d{2})(\\]|\\))$');
}
$value = DateRange::fromString($value);
}
return $value;
}
示例5: convertToDatabaseValue
/**
* {@inheritdoc}
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}
if ($value instanceof Carbon) {
return $value->copy()->setTimezone('UTC')->format($platform->getDateTimeFormatString());
}
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
}
示例6: convertToDatabaseValue
/**
* {@inheritdoc}
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (null === $value) {
return $value;
}
if (!$value instanceof \DateTime) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), self::MICRO_FORMAT);
}
return $value->format(self::MICRO_FORMAT);
}
开发者ID:p1x44r,项目名称:symfony-dbal-datetime-microsec,代码行数:13,代码来源:P1x44rSymfonyDbalDateTimeMicroSecType.php
示例7: convertToPHPValue
/**
* @see \Doctrine\DBAL\Types\Type::convertToPHPValue()
* @param string|null $sValue
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $oPlatform
* @return string|null
*/
public function convertToPHPValue($sValue, \Doctrine\DBAL\Platforms\AbstractPlatform $oPlatform)
{
$sValue = parent::convertToPHPValue($sValue, $oPlatform);
if (is_null($sValue)) {
return $sValue;
}
if ($sFilterValue = filter_var($sValue, FILTER_VALIDATE_IP)) {
return $sFilterValue;
}
throw \Doctrine\DBAL\Types\ConversionException::conversionFailedFormat($sValue, $this->getName(), 'valid IP adress');
}
示例8: convertToPHPValue
/**
* @param mixed $value
* @param AbstractPlatform $platform
* @return \DateTime|null
* @throws ConversionException
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}
$val = \DateTime::createFromFormat('!' . self::FORMAT, $value);
if (empty($val)) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), self::FORMAT);
}
return $val;
}
示例9: convertToPHPValue
/**
* @param \DateTimeImmutable|string|null $value
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
* @return \DateTimeImmutable|null
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null || $value instanceof DateTimeImmutable) {
return $value;
}
$dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getTimeFormatString(), $value);
if ($dateTime === false) {
throw \Doctrine\DBAL\Types\ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString());
}
return $dateTime;
}
示例10: convertToPHPValue
/**
* {@inheritDoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}
try {
return Decimal::create($value);
} catch (\Exception $e) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), '0.0');
}
}
示例11: convertToPHPValue
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null || $value instanceof \DateInterval) {
return $value;
}
try {
return new \DateInterval($value);
} catch (\Exception $exception) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), 'PY-m-dTH:i:s', $exception);
}
}
示例12: convertToPHPValue
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (null === $value || $value instanceof \DateTime) {
return $value;
}
$converted = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, self::$utc ? self::$utc : (self::$utc = new \DateTimeZone('UTC')));
if (!$converted) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
}
return $converted;
}
示例13: convertToPHPValue
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}
$val = DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, $this->getUTCInstance());
if ($val === false) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
}
return $val;
}
示例14: convertToPHPValue
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null || $value instanceof \DateTime) {
return $value;
}
$val = \DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString());
}
return $val;
}
示例15: convertToPHPValue
/**
* @param string $dateTimeString
* @param AbstractPlatform $platform
*
* @throws ConversionException
*
* @return DateTime|null
*/
public function convertToPHPValue($dateTimeString, AbstractPlatform $platform)
{
if (null === $dateTimeString || $dateTimeString instanceof DateTime) {
return $dateTimeString;
}
$dateTime = DateTime::createFromFormat($platform->getDateTimeFormatString(), $dateTimeString, self::getUtc());
if (!$dateTime) {
throw ConversionException::conversionFailedFormat($dateTimeString, $this->getName(), $platform->getDateTimeFormatString());
}
return $dateTime;
}