Ejemplo n.º 1
0
 /**
  * {@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());
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof Date) {
         return $value;
     }
     $val = Date::createFromFormat($platform->getDateTimeFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
     }
     return $val;
 }
Ejemplo n.º 4
0
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     $val = \Psc\DateTime\DateTime::parse($platform->getDateTimeFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
     }
     return $val;
 }
Ejemplo n.º 5
0
 /**
  * {@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;
 }
Ejemplo n.º 6
0
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === NULL) {
         return NULL;
     } elseif ($value instanceof \DateTime) {
         return NetteDateTime::from($value);
     }
     $val = NetteDateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
     }
     return NetteDateTime::from($val);
 }
 /**
  * @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->getDateTimeFormatString(), $value);
     if ($dateTime === false) {
         $dateTime = date_create_immutable($value);
     }
     if ($dateTime === false) {
         throw \Doctrine\DBAL\Types\ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
     }
     return $dateTime;
 }
Ejemplo n.º 8
0
 /**
  * @param \DateTimeImmutable|string|null $value
  * @param AbstractPlatform               $platform
  * @return \DateTimeImmutable|null
  * @throws ConversionException
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof \DateTimeImmutable) {
         return $value;
     }
     if (is_string($value)) {
         $dateTime = \DateTimeImmutable::createFromFormat($platform->getDateTimeFormatString(), $value);
         if ($dateTime !== false) {
             return $dateTime;
         }
     }
     if (is_array($value) || is_object($value)) {
         $value = print_r($value, true);
     }
     throw ConversionException::conversionFailedFormat((string) $value, $this->getName(), $platform->getDateTimeFormatString());
 }
Ejemplo n.º 9
0
 public function convertToDatabaseValue($timepoint, AbstractPlatform $platform)
 {
     if ($timepoint !== null) {
         $dtime = $timepoint->asPHPDateTime();
         return $dtime->format($platform->getDateTimeFormatString());
     }
 }
Ejemplo n.º 10
0
 /**
  * Find all revisions that were made of entity class with given id.
  *
  * @param string $className
  * @param mixed $id
  * @throws NotAuditedException
  * @return Revision[]
  */
 public function findRevisions($className, $id)
 {
     if (!$this->metadataFactory->isAudited($className)) {
         throw new NotAuditedException($className);
     }
     /** @var ClassMetadataInfo|ClassMetadata $class */
     $class = $this->em->getClassMetadata($className);
     $tableName = $this->config->getTableName($class);
     if (!is_array($id)) {
         $id = array($class->identifier[0] => $id);
     }
     $whereSQL = "";
     foreach ($class->identifier as $idField) {
         if (isset($class->fieldMappings[$idField])) {
             if ($whereSQL) {
                 $whereSQL .= " AND ";
             }
             $whereSQL .= "e." . $class->fieldMappings[$idField]['columnName'] . " = ?";
         } else {
             if (isset($class->associationMappings[$idField])) {
                 if ($whereSQL) {
                     $whereSQL .= " AND ";
                 }
                 $whereSQL .= "e." . $class->associationMappings[$idField]['joinColumns'][0] . " = ?";
             }
         }
     }
     $query = "SELECT r.* FROM " . $this->config->getRevisionTableName() . " r " . "INNER JOIN " . $tableName . " e ON r.id = e." . $this->config->getRevisionFieldName() . " WHERE " . $whereSQL . " ORDER BY r.id DESC";
     $revisionsData = $this->em->getConnection()->fetchAll($query, array_values($id));
     $revisions = array();
     foreach ($revisionsData as $row) {
         $revisions[] = new Revision($row['id'], \DateTime::createFromFormat($this->platform->getDateTimeFormatString(), $row['timestamp']), $row['username']);
     }
     return $revisions;
 }
Ejemplo n.º 11
0
 /**
  * @param DateTimeOfDay $value
  * @param AbstractPlatform $platform
  *
  * @return string
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if ($value instanceof DateTimeOfDay) {
         return $value->toDateTime()->format($platform->getDateTimeFormatString());
     }
     return parent::convertToDatabaseValue($value, $platform);
 }
Ejemplo n.º 12
0
 /**
  * Get the converted parameter list
  *
  * @param array $params
  * @param array $types
  * @return array
  */
 private function getConvertedParams($params, $types)
 {
     $result = array();
     foreach ($params as $position => $value) {
         if (isset($types[$position])) {
             $type = $types[$position];
             if (is_string($type)) {
                 $type = Type::getType($type);
             }
             if ($type instanceof Type) {
                 $value = $type->convertToDatabaseValue($value, $this->platform);
             }
         } else {
             if (is_object($value) && $value instanceof \DateTime) {
                 $value = $value->format($this->platform->getDateTimeFormatString());
             } elseif (!is_null($value)) {
                 $type = Type::getType(gettype($value));
                 $value = $type->convertToDatabaseValue($value, $this->platform);
             }
         }
         if (is_string($value)) {
             $value = "'{$value}'";
         } elseif (is_null($value)) {
             $value = 'NULL';
         }
         $result[$position] = $value;
     }
     return $result;
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($databaseValue, AbstractPlatform $platform)
 {
     if (null === $databaseValue || $databaseValue instanceof \DateTime) {
         return $databaseValue;
     }
     // The changed part is the following bloc where we put the DateTimeZone as the third argument rather than
     // relying on the local timezone
     $phpValue = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $databaseValue, new \DateTimeZone('UTC'));
     if (false === $phpValue) {
         $phpValue = date_create($databaseValue);
     }
     if (false === $phpValue) {
         throw ConversionException::conversionFailedFormat($databaseValue, $this->getName(), $platform->getDateTimeFormatString());
     }
     return $phpValue;
 }
 /** @noinspection PhpMissingParentCallCommonInspection
  * @inheritdoc
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     /** @var string|null $value */
     if ($value === null) {
         return null;
     }
     return $this->convertDateTimeString($value, $platform->getDateTimeFormatString(), static::JSON_API_FORMAT);
 }
 /** @noinspection PhpMissingParentCallCommonInspection
  * @inheritdoc
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     /** @var DateTime|null $value */
     if ($value === null) {
         return null;
     }
     return $value->format($platform->getDateTimeFormatString());
 }
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return $value;
     }
     if ($value instanceof DateTime) {
         return $value->setTimezone(new DateTimeZone('UTC'));
     }
     $dateTime = DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, new DateTimeZone('UTC'));
     if (!$dateTime) {
         $dateTime = date_create($value, new DateTimeZone('UTC'));
     }
     if (!$dateTime) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
     }
     return $dateTime;
 }
 /**
  * {@inheritdoc}
  *
  * @throws \RuntimeException If the data decode fails.
  */
 public function convertToPHPValue($value, AbstractPlatform $platform) : array
 {
     $raw = json_decode($value, true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new \RuntimeException(sprintf('The decode of the JSON string from the database ("%s") failed due to the following error: "%s"!', $value, json_last_error_msg()));
     }
     $dbFormat = $platform->getDateTimeFormatString();
     return array_map(function ($format) use($dbFormat) {
         return \DateTime::createFromFormat($dbFormat, $format);
     }, $raw);
 }
Ejemplo n.º 18
0
 /**
  * {@inheritDoc}
  */
 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('UTC')));
     if (!$val) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     return $val;
 }
Ejemplo n.º 19
0
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     $dateTimeFormatString = \Zend_Locale_Format::convertPhpToIsoFormat($platform->getDateTimeFormatString());
     $val = new \Zend_Date($value, $dateTimeFormatString);
     if (!$val) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     return $val;
 }
 /** @noinspection PhpMissingParentCallCommonInspection
  * @inheritdoc
  *
  * @SuppressWarnings(PHPMD.StaticAccess)
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     /** @var string|null|DateTime $value */
     if ($value === null) {
         return null;
     }
     $dateTime = $value instanceof DateTime ? $value : DateTime::createFromFormat(static::JSON_API_FORMAT, $value);
     if ($dateTime === false) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), static::JSON_API_FORMAT);
     }
     return $dateTime->format($platform->getDateTimeFormatString());
 }
 /** @noinspection PhpMissingParentCallCommonInspection
  * @inheritdoc
  *
  * @SuppressWarnings(PHPMD.StaticAccess)
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     /** @var string|null|DateTime $value */
     if ($value === null || $value instanceof DateTime) {
         return $value;
     }
     $dbFormat = $platform->getDateTimeFormatString();
     $dateTime = DateTime::createFromFormat($dbFormat, $value);
     if ($dateTime === false) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $dbFormat);
     }
     return $dateTime;
 }
Ejemplo n.º 22
0
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     if ($value === "") {
         return null;
     }
     //
     // returned format is too unpredictable, so have to resort to strtotime()
     $timestamp = strtotime($value);
     if ($timestamp === false) {
         $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
         //var_dump($value);exit;
         if (!$val) {
             throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
         }
     }
     $val = new \DateTime();
     $val->setTimestamp($timestamp);
     /*
             if(strpos($value, '.') !== false)
             {
        $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
        if (!$val) {
            throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
        }
             }
             else
             {
        $val = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
        if (!$val) {
            throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
        }
             }
     */
     return $val;
 }
Ejemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 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('UTC')));
     if (!$val) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     $errors = $val->getLastErrors();
     // date was parsed to completely not valid value
     if ($errors['warning_count'] > 0 && (int) $val->format('Y') < 0) {
         return null;
     }
     return $val;
 }
Ejemplo n.º 24
0
 /**
  * @param mixed            $value
  * @param AbstractPlatform $platform
  *
  * @return \DateTime|null
  * @throws ConversionException
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     if (!self::$utc) {
         self::$utc = new \DateTimeZone('UTC');
     }
     $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, self::$utc);
     if (!$val) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     //set to local timezone
     $tz = new \DateTimeZone(date_default_timezone_get());
     $val->setTimezone($tz);
     return $val;
 }
 public function testConvertToPHPValueReturnsUTCDateTimeForDateTimeValue()
 {
     $dateTime = DateTime::createFromFormat($this->abstractPlatform->getDateTimeFormatString(), '2014-11-27 13:16:31', new DateTimeZone('America/New_York'));
     $this->assertEquals('UTC', $this->dateTimeUTCType->convertToPHPValue($dateTime, $this->abstractPlatform)->getTimezone()->getName());
     $this->assertEquals('2014-11-27 18:16:31', $this->dateTimeUTCType->convertToPHPValue($dateTime, $this->abstractPlatform)->format($this->abstractPlatform->getDateTimeFormatString()));
 }
 /**
  * @param AbstractPlatform $platform
  *
  * @return string
  * @author Maximilian Ruta <*****@*****.**>
  */
 protected function getNullDateTime(AbstractPlatform $platform)
 {
     $format = $platform->getDateTimeFormatString();
     return str_replace(['Y', 'm', 'd', 'H', 'i', 's'], ['0000', '00', '00', '00', '00', '00'], $format);
 }
Ejemplo n.º 27
0
 /**
  * @param  string|null $value
  * @param  AbstractPlatform $platform
  * @return DateTime|null
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     return $this->doConvertToPHPValue($value, $platform->getDateTimeFormatString());
 }
Ejemplo n.º 28
0
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     return $value !== null ? \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value) : null;
 }
Ejemplo n.º 29
0
 /** @noinspection PhpMissingParentCallCommonInspection
  * @inheritdoc
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     /** @var string|null|DateTime $value */
     return $value instanceof DateTime ? $value->format($platform->getDateTimeFormatString()) : $value;
 }
 /**
  * @param mixed $value
  * @param Platforms\AbstractPlatform $platform
  *
  * @return string|NULL
  */
 public function convertToDatabaseValue($value, Platforms\AbstractPlatform $platform)
 {
     if ($value === NULL) {
         return NULL;
     }
     if (self::$utc === NULL) {
         self::$utc = new \DateTimeZone('UTC');
     }
     $value->setTimeZone(self::$utc);
     return $value->format($platform->getDateTimeFormatString());
 }