Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $sourceTargetEntity = $metaInformation->getEntity();
     $targetEntity = clone $sourceTargetEntity;
     $metaInformation->setEntity($targetEntity);
     return $this->valueHydrator->hydrate($document, $metaInformation);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $entityId = $metaInformation->getEntityId();
     $doctrineEntity = $this->doctrine->getManager()->getRepository($metaInformation->getClassName())->find($entityId);
     if ($doctrineEntity !== null) {
         $metaInformation->setEntity($doctrineEntity);
     }
     return $this->valueHydrator->hydrate($document, $metaInformation);
 }
Esempio n. 3
0
 /**
  * @param \ArrayAccess $document
  * @param object       $sourceTargetEntity
  *
  * @return object
  *
  * @throws \InvalidArgumentException if $sourceTargetEntity is null
  */
 public function toEntity(\ArrayAccess $document, $sourceTargetEntity)
 {
     if (null === $sourceTargetEntity) {
         throw new \InvalidArgumentException('$sourceTargetEntity should not be null');
     }
     $metaInformationFactory = new MetaInformationFactory();
     $metaInformation = $metaInformationFactory->loadInformation($sourceTargetEntity);
     $hydratedDocument = $this->indexHydrator->hydrate($document, $metaInformation);
     if ($this->hydrationMode == HydrationModes::HYDRATE_INDEX) {
         return $hydratedDocument;
     }
     $metaInformation->setEntity($hydratedDocument);
     if ($this->hydrationMode == HydrationModes::HYDRATE_DOCTRINE) {
         return $this->doctrineHydrator->hydrate($document, $metaInformation);
     }
 }
Esempio n. 4
0
 /**
  * @param \ArrayAccess $document
  * @param object       $sourceTargetEntity
  *
  * @return object
  *
  * @throws \InvalidArgumentException if $sourceTargetEntity is null
  */
 public function toEntity(\ArrayAccess $document, $sourceTargetEntity)
 {
     if (null === $sourceTargetEntity) {
         throw new \InvalidArgumentException('$sourceTargetEntity should not be null');
     }
     $metaInformation = $this->metaInformationFactory->loadInformation($sourceTargetEntity);
     if ($metaInformation->isDoctrineEntity() === false && $this->hydrationMode == HydrationModes::HYDRATE_DOCTRINE) {
         throw new \RuntimeException(sprintf('Please check your config. Given entity is not a Doctrine entity, but Doctrine hydration is enabled. Use setHydrationMode(HydrationModes::HYDRATE_DOCTRINE) to fix this.'));
     }
     $hydratedDocument = $this->indexHydrator->hydrate($document, $metaInformation);
     if ($this->hydrationMode == HydrationModes::HYDRATE_INDEX) {
         return $hydratedDocument;
     }
     $metaInformation->setEntity($hydratedDocument);
     if ($this->hydrationMode == HydrationModes::HYDRATE_DOCTRINE) {
         return $this->doctrineHydrator->hydrate($document, $metaInformation);
     }
 }