/** * 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; }
/** * Add a metadata object to the factory * * @param Metadata $meta * * @return MetadataRegistry self */ public function addMetadata(Metadata $meta) { $this->data[$meta->getClass()] = $meta; return $this; }
/** * Extract entity data * * @param object $entity * @param Metadata $metadata * * @return array */ protected function getEntityData($entity, Metadata $metadata) { $data = []; foreach ($metadata->getProperties() as $property) { if ($metadata->isReference($property)) { continue; } $data[$property->getName()] = $this->accessor->getValue($entity, $property->getName()); } return $data; }