本文整理匯總了PHP中Doctrine\DBAL\Types\ConversionException類的典型用法代碼示例。如果您正苦於以下問題:PHP ConversionException類的具體用法?PHP ConversionException怎麽用?PHP ConversionException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ConversionException類的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;
}
示例2: convertToPHPValue
/** {@inheritdoc} */
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (is_object($value)) {
throw ConversionException::conversionFailed($value, $this);
}
return null === $value ? null : (int) $value;
}
示例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());
}
}
示例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);
}
示例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;
}
示例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');
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}