/** * 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; }
/** * Clean query parameters by converting via the types defined by the properties * * @param Query $query * * @return array */ protected function cleanParameters(Query $query) { $params = $query->getParameters(); $references = $query->getReferences(); $variables = $query->getVariables(); foreach ($params as $key => &$values) { if (!isset($references[$key])) { continue; } foreach ($values as $k => &$value) { if (!isset($references[$key][$k])) { continue; } list($var, $prop) = explode('.', $references[$key][$k]); $class = $this->identityMap->getClass($variables[$var]); $metadata = $this->metadataRegistry->getMetadata($class); if (!$metadata->hasProperty($prop)) { continue; } $prop = $metadata->getProperty($prop); if ($prop->isNullable() && $value === null) { unset($values[$k]); continue; } $value = Types::getType($prop->getType())->convertToDatabaseValue($value, $prop); } } return $params; }
/** * Create an entity * * @param Metadata $meta * @param array $properties * * @return object */ protected function createEntity(Metadata $meta, array $properties) { $class = $meta->getClass(); $id = $properties[$meta->getId()->getProperty()]; if ($this->entities->has($class, $id)) { return $this->entities->get($class, $id); } $entity = $this->proxyFactory->createProxy($class, function (LazyLoadingInterface $proxy, $method, array $parameters, &$initializer) { $this->lazyLoad($proxy, $initializer); }); $data = []; foreach ($properties as $property => $value) { if (!$meta->hasProperty($property)) { continue; } $property = $meta->getProperty($property); $data[$property->getName()] = Types::getType($property->getType())->convertToPHPValue($value, $property); } $this->entities->add($entity, $class, $id, ['properties' => $data]); return $entity; }