createEntity() public method

INTERNAL: Creates an entity. Used for reconstitution of persistent entities.
public createEntity ( string $className, array $data, array &$hints = [] ) : object
$className string The name of the entity class.
$data array The data for the entity.
$hints array Any hints to account for during reconstitution/lookup of the entity.
return object The managed entity instance.
 /**
  * {@inheritdoc}
  */
 public function loadCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, EntityCacheEntry $entry, $entity = null)
 {
     $data = $entry->data;
     $hints = self::$hints;
     if ($entity !== null) {
         $hints[Query::HINT_REFRESH] = true;
         $hints[Query::HINT_REFRESH_ENTITY] = $entity;
     }
     foreach ($metadata->associationMappings as $name => $assoc) {
         if (!isset($assoc['cache']) || !isset($data[$name])) {
             continue;
         }
         $assocClass = $data[$name]->class;
         $assocId = $data[$name]->identifier;
         $isEagerLoad = $assoc['fetch'] === ClassMetadata::FETCH_EAGER || $assoc['type'] === ClassMetadata::ONE_TO_ONE && !$assoc['isOwningSide'];
         if (!$isEagerLoad) {
             $data[$name] = $this->em->getReference($assocClass, $assocId);
             continue;
         }
         $assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId);
         $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
         $assocRegion = $assocPersister->getCacheRegion();
         $assocEntry = $assocRegion->get($assocKey);
         if ($assocEntry === null) {
             return null;
         }
         $data[$name] = $this->uow->createEntity($assocEntry->class, $assocEntry->resolveAssociationEntries($this->em), $hints);
     }
     if ($entity !== null) {
         $this->uow->registerManaged($entity, $key->identifier, $data);
     }
     $result = $this->uow->createEntity($entry->class, $data, $hints);
     $this->uow->hydrationComplete();
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection)
 {
     $assoc = $metadata->associationMappings[$key->association];
     $targetPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
     $targetRegion = $targetPersister->getCacheRegion();
     $list = array();
     foreach ($entry->identifiers as $index => $identifier) {
         $entityEntry = $targetRegion->get(new EntityCacheKey($assoc['targetEntity'], $identifier));
         if ($entityEntry === null) {
             return null;
         }
         $list[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->data, self::$hints);
     }
     array_walk($list, function ($entity, $index) use($collection) {
         $collection->hydrateSet($index, $entity);
     });
     return $list;
 }
 /**
  * {@inheritdoc}
  */
 public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection)
 {
     $assoc = $metadata->associationMappings[$key->association];
     /* @var $targetPersister \Doctrine\ORM\Cache\Persister\CachedPersister */
     $targetPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
     $targetRegion = $targetPersister->getCacheRegion();
     $list = [];
     $entityEntries = $targetRegion->getMultiple($entry);
     if ($entityEntries === null) {
         return null;
     }
     /* @var $entityEntries \Doctrine\ORM\Cache\EntityCacheEntry[] */
     foreach ($entityEntries as $index => $entityEntry) {
         $list[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->resolveAssociationEntries($this->em), self::$hints);
     }
     array_walk($list, function ($entity, $index) use($collection) {
         $collection->hydrateSet($index, $entity);
     });
     $this->uow->hydrationComplete();
     return $list;
 }
 /**
  * {@inheritdoc}
  */
 public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = array())
 {
     if (!($key->cacheMode & Cache::MODE_GET)) {
         return null;
     }
     $entry = $this->region->get($key);
     if (!$entry instanceof QueryCacheEntry) {
         return null;
     }
     if (!$this->validator->isValid($key, $entry)) {
         $this->region->evict($key);
         return null;
     }
     $result = array();
     $entityName = reset($rsm->aliasMap);
     $hasRelation = !empty($rsm->relationMap);
     $persister = $this->uow->getEntityPersister($entityName);
     $region = $persister->getCacheRegion();
     $regionName = $region->getName();
     // @TODO - move to cache hydration component
     foreach ($entry->result as $index => $entry) {
         if (($entityEntry = $region->get($entityKey = new EntityCacheKey($entityName, $entry['identifier']))) === null) {
             if ($this->cacheLogger !== null) {
                 $this->cacheLogger->entityCacheMiss($regionName, $entityKey);
             }
             return null;
         }
         if ($this->cacheLogger !== null) {
             $this->cacheLogger->entityCacheHit($regionName, $entityKey);
         }
         if (!$hasRelation) {
             $result[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->resolveAssociationEntries($this->em), self::$hints);
             continue;
         }
         $data = $entityEntry->data;
         foreach ($entry['associations'] as $name => $assoc) {
             $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
             $assocRegion = $assocPersister->getCacheRegion();
             if ($assoc['type'] & ClassMetadata::TO_ONE) {
                 if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assoc['identifier']))) === null) {
                     if ($this->cacheLogger !== null) {
                         $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey);
                     }
                     $this->uow->hydrationComplete();
                     return null;
                 }
                 $data[$name] = $this->uow->createEntity($assocEntry->class, $assocEntry->resolveAssociationEntries($this->em), self::$hints);
                 if ($this->cacheLogger !== null) {
                     $this->cacheLogger->entityCacheHit($assocRegion->getName(), $assocKey);
                 }
                 continue;
             }
             if (!isset($assoc['list']) || empty($assoc['list'])) {
                 continue;
             }
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             $collection = new PersistentCollection($this->em, $targetClass, new ArrayCollection());
             foreach ($assoc['list'] as $assocIndex => $assocId) {
                 if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId))) === null) {
                     if ($this->cacheLogger !== null) {
                         $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey);
                     }
                     $this->uow->hydrationComplete();
                     return null;
                 }
                 $element = $this->uow->createEntity($assocEntry->class, $assocEntry->resolveAssociationEntries($this->em), self::$hints);
                 $collection->hydrateSet($assocIndex, $element);
                 if ($this->cacheLogger !== null) {
                     $this->cacheLogger->entityCacheHit($assocRegion->getName(), $assocKey);
                 }
             }
             $data[$name] = $collection;
             $collection->setInitialized(true);
         }
         $result[$index] = $this->uow->createEntity($entityEntry->class, $data, self::$hints);
     }
     $this->uow->hydrationComplete();
     return $result;
 }