当前位置: 首页>>代码示例>>PHP>>正文


PHP UnitOfWork::getEntityPersister方法代码示例

本文整理汇总了PHP中Doctrine\ORM\UnitOfWork::getEntityPersister方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::getEntityPersister方法的具体用法?PHP UnitOfWork::getEntityPersister怎么用?PHP UnitOfWork::getEntityPersister使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\UnitOfWork的用法示例。


在下文中一共展示了UnitOfWork::getEntityPersister方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadCacheEntry

 /**
  * {@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;
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:38,代码来源:DefaultEntityHydrator.php

示例2: storeAssociationCache

 /**
  * @param \Doctrine\ORM\Cache\QueryCacheKey $key
  * @param array                             $assoc
  * @param mixed                             $assocValue
  *
  * @return array|null
  */
 private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocValue)
 {
     $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
     $assocMetadata = $assocPersister->getClassMetadata();
     $assocRegion = $assocPersister->getCacheRegion();
     // Handle *-to-one associations
     if ($assoc['type'] & ClassMetadata::TO_ONE) {
         $assocIdentifier = $this->uow->getEntityIdentifier($assocValue);
         $entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier);
         if (!$assocValue instanceof Proxy && $key->cacheMode & Cache::MODE_REFRESH || !$assocRegion->contains($entityKey)) {
             // Entity put fail
             if (!$assocPersister->storeEntityCache($assocValue, $entityKey)) {
                 return null;
             }
         }
         return ['targetEntity' => $assocMetadata->rootEntityName, 'identifier' => $assocIdentifier, 'type' => $assoc['type']];
     }
     // Handle *-to-many associations
     $list = [];
     foreach ($assocValue as $assocItemIndex => $assocItem) {
         $assocIdentifier = $this->uow->getEntityIdentifier($assocItem);
         $entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier);
         if ($key->cacheMode & Cache::MODE_REFRESH || !$assocRegion->contains($entityKey)) {
             // Entity put fail
             if (!$assocPersister->storeEntityCache($assocItem, $entityKey)) {
                 return null;
             }
         }
         $list[$assocItemIndex] = $assocIdentifier;
     }
     return ['targetEntity' => $assocMetadata->rootEntityName, 'type' => $assoc['type'], 'list' => $list];
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:39,代码来源:DefaultQueryCache.php

示例3: storeCollectionCache

 /**
  * {@inheritdoc}
  */
 public function storeCollectionCache(CollectionCacheKey $key, $elements)
 {
     $targetPersister = $this->uow->getEntityPersister($this->targetEntity->rootEntityName);
     $targetRegion = $targetPersister->getCacheRegion();
     $targetHydrator = $targetPersister->getEntityHydrator();
     $entry = $this->hydrator->buildCacheEntry($this->targetEntity, $key, $elements);
     foreach ($entry->identifiers as $index => $identifier) {
         $entityKey = new EntityCacheKey($this->targetEntity->rootEntityName, $identifier);
         if ($targetRegion->contains($entityKey)) {
             continue;
         }
         $class = $this->targetEntity;
         $className = ClassUtils::getClass($elements[$index]);
         if ($className !== $this->targetEntity->name) {
             $class = $this->metadataFactory->getMetadataFor($className);
         }
         $entity = $elements[$index];
         $entityEntry = $targetHydrator->buildCacheEntry($class, $entityKey, $entity);
         $targetRegion->put($entityKey, $entityEntry);
     }
     $cached = $this->region->put($key, $entry);
     if ($this->cacheLogger && $cached) {
         $this->cacheLogger->collectionCachePut($this->regionName, $key);
     }
 }
开发者ID:svobodni,项目名称:web,代码行数:28,代码来源:AbstractCollectionPersister.php

示例4: loadCacheEntry

 /**
  * {@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;
 }
开发者ID:svobodni,项目名称:web,代码行数:21,代码来源:DefaultCollectionHydrator.php

示例5: evictElementCache

 /**
  * @param string $targetEntity
  * @param object $element
  */
 protected function evictElementCache($targetEntity, $element)
 {
     /* @var $targetPersister CachedEntityPersister */
     $targetPersister = $this->uow->getEntityPersister($targetEntity);
     $targetRegion = $targetPersister->getCacheRegion();
     $key = new EntityCacheKey($targetEntity, $this->uow->getEntityIdentifier($element));
     $targetRegion->evict($key);
     if ($this->cacheLogger) {
         $this->cacheLogger->entityCachePut($targetRegion->getName(), $key);
     }
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:15,代码来源:AbstractCollectionPersister.php

示例6: evictEntityRegions

 /**
  * {@inheritdoc}
  */
 public function evictEntityRegions()
 {
     $metadatas = $this->em->getMetadataFactory()->getAllMetadata();
     foreach ($metadatas as $metadata) {
         $persister = $this->uow->getEntityPersister($metadata->rootEntityName);
         if (!$persister instanceof CachedPersister) {
             continue;
         }
         $persister->getCacheRegion()->evictAll();
     }
 }
开发者ID:Dren-x,项目名称:mobitnew,代码行数:14,代码来源:DefaultCache.php

示例7: loadCacheEntry

 /**
  * {@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;
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:24,代码来源:DefaultCollectionHydrator.php

示例8: storeJoinedAssociations

 /**
  * @param object $entity
  */
 private function storeJoinedAssociations($entity)
 {
     if ($this->joinedAssociations === null) {
         $associations = array();
         foreach ($this->class->associationMappings as $name => $assoc) {
             if (isset($assoc['cache']) && $assoc['type'] & ClassMetadata::TO_ONE && ($assoc['fetch'] === ClassMetadata::FETCH_EAGER || !$assoc['isOwningSide'])) {
                 $associations[] = $name;
             }
         }
         $this->joinedAssociations = $associations;
     }
     foreach ($this->joinedAssociations as $name) {
         $assoc = $this->class->associationMappings[$name];
         $assocEntity = $this->class->getFieldValue($entity, $name);
         if ($assocEntity === null) {
             continue;
         }
         $assocId = $this->uow->getEntityIdentifier($assocEntity);
         $assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId);
         $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
         $assocPersister->storeEntityCache($assocEntity, $assocKey);
     }
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:26,代码来源:AbstractEntityPersister.php

示例9: put

 /**
  * {@inheritdoc}
  */
 public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $hints = array())
 {
     if ($rsm->scalarMappings) {
         throw new CacheException("Second level cache does not support scalar results.");
     }
     if (count($rsm->entityMappings) > 1) {
         throw new CacheException("Second level cache does not support multiple root entities.");
     }
     if (!$rsm->isSelect) {
         throw new CacheException("Second-level cache query supports only select statements.");
     }
     if (isset($hints[Query::HINT_FORCE_PARTIAL_LOAD]) && $hints[Query::HINT_FORCE_PARTIAL_LOAD]) {
         throw new CacheException("Second level cache does not support partial entities.");
     }
     if (!($key->cacheMode & Cache::MODE_PUT)) {
         return false;
     }
     $data = array();
     $entityName = reset($rsm->aliasMap);
     $hasRelation = !empty($rsm->relationMap);
     $metadata = $this->em->getClassMetadata($entityName);
     $persister = $this->uow->getEntityPersister($entityName);
     if (!$persister instanceof CachedPersister) {
         throw CacheException::nonCacheableEntity($entityName);
     }
     $region = $persister->getCacheRegion();
     foreach ($result as $index => $entity) {
         $identifier = $this->uow->getEntityIdentifier($entity);
         $data[$index]['identifier'] = $identifier;
         $data[$index]['associations'] = array();
         if ($key->cacheMode & Cache::MODE_REFRESH || !$region->contains($entityKey = new EntityCacheKey($entityName, $identifier))) {
             // Cancel put result if entity put fail
             if (!$persister->storeEntityCache($entity, $entityKey)) {
                 return false;
             }
         }
         if (!$hasRelation) {
             continue;
         }
         // @TODO - move to cache hydration components
         foreach ($rsm->relationMap as $name) {
             $assoc = $metadata->associationMappings[$name];
             if (($assocValue = $metadata->getFieldValue($entity, $name)) === null || $assocValue instanceof Proxy) {
                 continue;
             }
             if (!isset($assoc['cache'])) {
                 throw CacheException::nonCacheableEntityAssociation($entityName, $name);
             }
             $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
             $assocRegion = $assocPersister->getCacheRegion();
             $assocMetadata = $assocPersister->getClassMetadata();
             // Handle *-to-one associations
             if ($assoc['type'] & ClassMetadata::TO_ONE) {
                 $assocIdentifier = $this->uow->getEntityIdentifier($assocValue);
                 if ($key->cacheMode & Cache::MODE_REFRESH || !$assocRegion->contains($entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier))) {
                     // Cancel put result if association entity put fail
                     if (!$assocPersister->storeEntityCache($assocValue, $entityKey)) {
                         return false;
                     }
                 }
                 $data[$index]['associations'][$name] = array('targetEntity' => $assocMetadata->rootEntityName, 'identifier' => $assocIdentifier, 'type' => $assoc['type']);
                 continue;
             }
             // Handle *-to-many associations
             $list = array();
             foreach ($assocValue as $assocItemIndex => $assocItem) {
                 $assocIdentifier = $this->uow->getEntityIdentifier($assocItem);
                 if ($key->cacheMode & Cache::MODE_REFRESH || !$assocRegion->contains($entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier))) {
                     // Cancel put result if entity put fail
                     if (!$assocPersister->storeEntityCache($assocItem, $entityKey)) {
                         return false;
                     }
                 }
                 $list[$assocItemIndex] = $assocIdentifier;
             }
             $data[$index]['associations'][$name] = array('targetEntity' => $assocMetadata->rootEntityName, 'type' => $assoc['type'], 'list' => $list);
         }
     }
     return $this->region->put($key, new QueryCacheEntry($data));
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:83,代码来源:DefaultQueryCache.php

示例10: getEntityPersister

 /**
  * @override
  */
 public function getEntityPersister($entityName)
 {
     return isset($this->_persisterMock[$entityName]) ? $this->_persisterMock[$entityName] : parent::getEntityPersister($entityName);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:7,代码来源:UnitOfWorkMock.php

示例11: onFlush

 public function onFlush(OnFlushEventArgs $eventArgs)
 {
     if (!$this->active) {
         return;
     }
     // Clear updateData
     $this->updateData = $this->extraUpdates = array();
     $this->em = $eventArgs->getEntityManager();
     $this->conn = $this->em->getConnection();
     $this->uow = $this->em->getUnitOfWork();
     $this->platform = $this->conn->getDatabasePlatform();
     $this->revisionId = null;
     // reset revision
     $this->draft = false;
     $processedEntities = array();
     foreach ($this->uow->getScheduledEntityDeletions() as $entity) {
         if (!$this->annotationReader->isRevised(get_class($entity), true)) {
             continue;
         }
         //doctrine is fine deleting elements multiple times. We are not.
         $hash = $this->getHash($entity);
         if (in_array($hash, $processedEntities)) {
             continue;
         }
         $processedEntities[] = $hash;
         $this->extraUpdates[spl_object_hash($entity)] = $entity;
         $persister = $this->uow->getEntityPersister(get_class($entity));
         $this->updateData[spl_object_hash($entity)] = $this->prepareUpdateData($persister, $entity);
         $entityData = array_merge($this->getOriginalEntityData($entity), $this->uow->getEntityIdentifier($entity));
         $this->saveRevisionEntityData($this->em->getClassMetadata(get_class($entity)), $entityData, 'DEL');
         if ($this->annotationReader->isDraft($entity) && $entity->isDraft()) {
             $this->resetRevisedData($entity);
             $this->setRevisionInfo($entity);
             $persister = $this->uow->getEntityPersister(get_class($entity));
             $this->updateData[spl_object_hash($entity)] = $this->prepareUpdateData($persister, $entity);
             $fieldName = 'deletedAt';
             $reflProp = new \ReflectionProperty($entity, $fieldName);
             $reflProp->setAccessible(true);
             $oldValue = $reflProp->getValue($entity);
             $reflProp->setValue($entity, null);
             $this->uow->scheduleExtraUpdate($entity, array($fieldName => array($oldValue, null)));
         }
         if (isset($this->softDeletes[spl_object_hash($entity)])) {
             $this->em->persist($entity);
         }
     }
     foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
         if (!$this->annotationReader->isRevised(get_class($entity), true)) {
             continue;
         }
         $this->setRevisionInfo($entity);
         $this->extraUpdates[spl_object_hash($entity)] = $entity;
         $persister = $this->uow->getEntityPersister(get_class($entity));
         $this->updateData[spl_object_hash($entity)] = $this->prepareUpdateData($persister, $entity);
         if ($this->annotationReader->isDraft($entity) && $entity->isDraft()) {
             $this->insertDrafts[spl_object_hash($entity)] = $entity;
             $this->resetRevisedData($entity);
             $this->uow->recomputeSingleEntityChangeSet($this->em->getClassMetadata(get_class($entity)), $entity);
         }
     }
     foreach ($this->uow->getScheduledEntityUpdates() as $entity) {
         if (!$this->annotationReader->isRevised(get_class($entity), true)) {
             continue;
         }
         $this->setRevisionInfo($entity);
         $this->extraUpdates[spl_object_hash($entity)] = $entity;
         $persister = $this->uow->getEntityPersister(get_class($entity));
         $this->updateData[spl_object_hash($entity)] = $this->prepareUpdateData($persister, $entity);
         if ($this->annotationReader->isDraft($entity) && $entity->isDraft()) {
             $this->resetRevisedData($entity);
         }
     }
 }
开发者ID:opifer,项目名称:revisions,代码行数:73,代码来源:RevisionListener.php


注:本文中的Doctrine\ORM\UnitOfWork::getEntityPersister方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。