private function replacePlaceholder(Property $property) { $type = $property->getType(); if ($property->isBasicType()) { if (array_key_exists($type, self::$placeholders)) { return self::$placeholders[$type]; } else { return self::$defaultPlaceholder; } } else { if ($type === 'DateTime' || is_subclass_of($type, 'DateTime')) { if ($property->hasCustomFlag(self::$typeFlagName) && preg_match('#^(DATE|Date|date)$#', $property->getCustomFlagValue(self::$typeFlagName))) { return self::$placeholders['Date']; } else { return self::$placeholders['DateTime']; } } else { return self::$defaultPlaceholder; } } }
/** * @param Property $property * @param string $mapperClass * @param Entity $entity * @throws InvalidValueException */ private function checkConsistency(Property $property, $mapperClass, Entity $entity) { $type = $property->getType(); if (!$entity instanceof $type) { throw new InvalidValueException("Inconsistency found: property '{$property->getName()}' in entity " . get_called_class() . " is supposed to contain an instance of '{$type}' (due to type hint), but mapper maps it to '{$mapperClass}'. Please fix getEntityClass method in mapper, property annotation or entities inheritance."); } }
private function getType(Property $property) { $type = NULL; if ($property->isBasicType()) { $type = $property->getType(); if ($type == 'string') { if (!$property->hasCustomFlag('size')) { $type = 'text'; } } /* if ($property->containsEnumeration()) { $type = 'enum'; } */ } else { // Objects $class = new ReflectionClass($property->getType()); $class = $class->newInstance(); if ($class instanceof DateTime) { if ($property->hasCustomFlag('format')) { $type = $property->getCustomFlagValue('format'); } else { $type = 'datetime'; } } } return $type; }
private function getType(Property $property) { $type = null; if ($property->isBasicType()) { $type = $property->getType(); if ($type == 'string') { if ($property->hasCustomFlag('type')) { $type = $property->getCustomFlagValue('type'); } else { if (!$property->hasCustomFlag('size') || $property->getCustomFlagValue('size') >= 65536) { $type = 'text'; } } } } else { // Objects $reflectionClass = new \ReflectionClass($property->getType()); $object = $reflectionClass->newInstance(); if ($object instanceof \DateTime) { if ($property->hasCustomFlag('type')) { $types = explode(':', strtolower($property->getCustomFlagValue('type'))); switch ($types[0]) { case 'date': case 'datetime': case 'timestamp': $type = $types[0]; break; default: throw new InvalidArgumentException(sprintf('DateTime property does not accept custom flag m:type(%s)', $types[0])); break; } } else { $type = 'datetime'; } } } return $type; }