當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ConversionException::conversionFailed方法代碼示例

本文整理匯總了PHP中Doctrine\DBAL\Types\ConversionException::conversionFailed方法的典型用法代碼示例。如果您正苦於以下問題:PHP ConversionException::conversionFailed方法的具體用法?PHP ConversionException::conversionFailed怎麽用?PHP ConversionException::conversionFailed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\DBAL\Types\ConversionException的用法示例。


在下文中一共展示了ConversionException::conversionFailed方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

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

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

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

示例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}
  *
  * @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

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

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

示例12: convertToPHPValue

 /**
  * Converts a value from its database representation to its PHP representation
  * of this type.
  *
  * @param mixed $value The value to convert.
  * @param AbstractPlatform $platform The currently used database platform.
  * @return mixed The PHP representation of the value.
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if (is_string($value)) {
         $value = fopen('data://text/plain;base64,' . base64_encode($value), 'r');
     } else {
         if (!is_resource($value)) {
             throw ConversionException::conversionFailed($value, self::BLOB);
         }
     }
     return $value;
 }
開發者ID:SerdarSanri,項目名稱:doctrine-bundle,代碼行數:19,代碼來源:BlobType.php

示例13: convertToDatabaseValue

 /**
  * Convert to Database Value
  *
  * @access public
  * @param \Darsyn\IP\IP $value
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @throws \Doctrine\DBAL\Types\ConversationException
  * @return void
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return;
     }
     try {
         return (string) ($value instanceof IP ? $value : new IP($value));
     } catch (InvalidIpAddressException $e) {
         throw ConversionException::conversionFailed($value, static::NAME);
     }
 }
開發者ID:darsyn,項目名稱:ip,代碼行數:20,代碼來源:IpType.php

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

示例15: convertToPHPValue

 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     $val = \DateTime::createFromFormat('!' . $platform->getDateFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     return $val;
 }
開發者ID:michaelnavarro,項目名稱:zc,代碼行數:11,代碼來源:DateType.php


注:本文中的Doctrine\DBAL\Types\ConversionException::conversionFailed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。