/** * {@inheritdoc} */ public function convertToDatabaseValue($value, Property $property) { if (is_string($value)) { $value = new \DateTime($value); } if (!is_object($value) && !$value instanceof \DateTime) { throw new \InvalidArgumentException(sprintf('Property "%s" must be a string or a DateTime object', $property->getName())); } return $value->format(\DateTime::ISO8601); }
/** * Use inner type to convert each array's value * * @param mixed $value * @param Property $property * @param string $method * * @return array */ protected function convert($value, Property $property, $method) { if (!$property->hasOption('inner_type')) { throw new IncompletePropertyDefinitionException(sprintf('An inner type must be defined for the property "%s"', $property->getName())); } $value = (array) $value; $type = Types::getType($property->getOption('inner_type')); if ($type instanceof self) { throw new \LogicException('Array imbrication is not allowed'); } foreach ($value as &$val) { $val = $type->{$method}($val, $property); } return $value; }