Doctrine\ORM\UnitOfWork::getEntityPersister PHP Method

getEntityPersister() public method

Gets the EntityPersister for an Entity.
public getEntityPersister ( string $entityName ) : Doctrine\ORM\Persister\AbstractEntityPersister
$entityName string The name of the Entity.
return Doctrine\ORM\Persister\AbstractEntityPersister
    public function getEntityPersister($entityName)
    {
        if ( ! isset($this->persisters[$entityName])) {
            $class = $this->em->getClassMetadata($entityName);
            if ($class->isInheritanceTypeNone()) {
                $persister = new Persisters\BasicEntityPersister($this->em, $class);
            } else if ($class->isInheritanceTypeSingleTable()) {
                $persister = new Persisters\SingleTablePersister($this->em, $class);
            } else if ($class->isInheritanceTypeJoined()) {
                $persister = new Persisters\JoinedSubclassPersister($this->em, $class);
            } else {
                $persister = new Persisters\UnionSubclassPersister($this->em, $class);
            }
            $this->persisters[$entityName] = $persister;
        }
        return $this->persisters[$entityName];
    }

Usage Example

 /**
  * {@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;
 }
All Usage Examples Of Doctrine\ORM\UnitOfWork::getEntityPersister