• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Types\ConversionException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Doctrine\DBAL\Types\ConversionException的典型用法代码示例。如果您正苦于以下问题:PHP ConversionException类的具体用法?PHP ConversionException怎么用?PHP ConversionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ConversionException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: convertToPHPValue

 /**
  * (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;
 }
开发者ID:ramunasd,项目名称:doctrine-psql,代码行数:36,代码来源:IntervalType.php


示例2: convertToPHPValue

 /** {@inheritdoc} */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if (is_object($value)) {
         throw ConversionException::conversionFailed($value, $this);
     }
     return null === $value ? null : (int) $value;
 }
开发者ID:ntd1712,项目名称:common,代码行数:8,代码来源:TinyIntType.php


示例3: convertToDatabaseValue

 /**
  * @param OrderState $value
  * @param AbstractPlatform $platform
  * @return array|string
  * @throws ConversionException
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (is_null($value)) {
         return [];
     }
     if (!$value instanceof OrderState) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     switch (get_class($value)) {
         case OrderState\Accepted::class:
             return 1;
         case OrderState\Created::class:
             return 2;
         case OrderState\Prepared::class:
             return 3;
         case OrderState\Refunded::class:
             return 4;
         case OrderState\Rejected::class:
             return 5;
         case OrderState\Sent::class:
             return 6;
         default:
             throw ConversionException::conversionFailed($value, $this->getName());
     }
 }
开发者ID:dumplie,项目名称:dumplie,代码行数:31,代码来源:OrderStateType.php


示例4: convertToDatabaseValue

 /**
  * {@inheritdoc}
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (!$value instanceof Coordinate) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     $data = [$value->getLatitude(), $value->getLongitude(), $value->isNoWrap()];
     return parent::convertToDatabaseValue($data, $platform);
 }
开发者ID:ekyna,项目名称:GoogleBundle,代码行数:11,代码来源:CoordinateType.php


示例5: 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;
 }
开发者ID:limoncello-php,项目名称:json-api,代码行数:20,代码来源:DateTimeDefaultStringType.php


示例6: 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');
 }
开发者ID:zf2-boiler-app,项目名称:app-logger,代码行数:16,代码来源:RequestHeadersType.php


示例7: convertToDatabaseValue

 /**
  * {@inheritdoc}
  *
  * @param ShortId|null                              $value
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return;
     }
     if ($value instanceof ShortId || ShortId::isValid($value)) {
         return $value;
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
开发者ID:pugx,项目名称:shortid-doctrine,代码行数:16,代码来源:ShortidType.php


示例8: convertToDatabaseValue

 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof Price) {
         return (string) PricePresentation::stringifyPrice($value);
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
开发者ID:leaphly,项目名称:price,代码行数:10,代码来源:DoctrineORMPriceType.php


示例9: 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


示例10: convertToDatabaseValue

 /**
  * {@inheritdoc}
  *
  * @param TrackingId|null $value
  * @param AbstractPlatform $platform
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (null === $value) {
         return null;
     }
     if ($value instanceof TrackingId) {
         return $value->toString();
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
开发者ID:RossJHagan,项目名称:php-ddd-cargo-sample,代码行数:16,代码来源:TrackingIdDoctrineType.php


示例11: 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());
 }
开发者ID:Zn4rK,项目名称:laravel-template,代码行数:13,代码来源:CarbonType.php


示例12: 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;
 }
开发者ID:epoplive,项目名称:dateintervalbundle,代码行数:13,代码来源:DateIntervalType.php


示例13: convertToDatabaseValue

 /**
  * {@inheritdoc}
  *
  * @param Uuid|null                                 $value
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof Uuid) {
         return (string) $value;
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
开发者ID:brambravo,项目名称:webtrees,代码行数:16,代码来源:UuidType.php


示例14: convertToDatabaseValue

 /**
  * {@inheritdoc}
  *
  * @param Uuid|null                                 $value
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof Uuid || Uuid::isValid($value)) {
         return $value->getBytes();
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
开发者ID:EdgarPE,项目名称:uuid-doctrine,代码行数:16,代码来源:UuidBinaryType.php


示例15: convertToDatabaseValue

 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof Money) {
         return (string) $value->getCurrency() . ' ' . $value->getAmount();
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
开发者ID:lakhman,项目名称:TbbcMoneyBundle,代码行数:10,代码来源:MoneyType.php


示例16: convertToDatabaseValue

 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (null === $value) {
         return null;
     }
     if (!is_array($value)) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     return Coder::encode($value);
 }
开发者ID:intaro,项目名称:hstore-extension,代码行数:10,代码来源:HStoreType.php


示例17: 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;
 }
开发者ID:salamek,项目名称:doctrine-daterange,代码行数:17,代码来源:DateRangeType.php


示例18: 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');
     }
 }
开发者ID:coolms,项目名称:doctrine,代码行数:14,代码来源:DecimalObject.php


示例19: 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;
 }
开发者ID:roelvanduijnhoven,项目名称:Doctrine-Date-Time-Immutable-Types,代码行数:16,代码来源:TimeImmutableType.php


示例20: convertToPHPValue

 /**
  * @throws ConversionException
  * @param string $value
  * @param AbstractPlatform $platform
  * @return DateTime
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof \DateTime) {
         return $value;
     }
     $val = date_create($value);
     if (!$val) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     return $val;
 }
开发者ID:rdohms,项目名称:dbal,代码行数:17,代码来源:VarDateTimeType.php



注:本文中的Doctrine\DBAL\Types\ConversionException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Types\Type类代码示例发布时间:2022-05-23
下一篇:
PHP Schema\Table类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap