/** * (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; }
/** {@inheritdoc} */ public function convertToPHPValue($value, AbstractPlatform $platform) { if (is_object($value)) { throw ConversionException::conversionFailed($value, $this); } return null === $value ? null : (int) $value; }
/** * @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()); } }
/** * {@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); }
/** * @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; }
/** * @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'); }
/** * {@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); }
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); }
/** * {@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); }
/** * {@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); }
/** * {@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()); }
/** * @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; }
/** * {@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); }
/** * {@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); }
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); }
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); }
/** * @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; }
/** * {@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'); } }
/** * @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; }
/** * @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; }
/** * 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; }
/** * @param string|null $value * @param string $formatString * @return DateTime|null * @throws ConversionException */ public function doConvertToPHPValue($value, $formatString) { if ($value === null) { return null; } $dateTime = DateTime::createFromFormat('!' . $formatString, $value, self::$utcTimezone ?: (self::$utcTimezone = new DateTimeZone('utc'))); if (!$dateTime) { throw ConversionException::conversionFailed($value, $this->getName()); } return $dateTime; }
/** * {@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; }
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; }
/** * @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; }
public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { return null; } $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, self::$utc ? self::$utc : (self::$utc = new \DateTimeZone(\DateTimeZone::UTC))); if (!$val) { throw ConversionException::conversionFailed($value, $this->getName()); } return $val; }
/** * @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'); }
/** * @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; }
/** * {@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; }
/** * {@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); } }