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


PHP UnitOfWork::getSingleIdentifierValue方法代码示例

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


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

示例1: find

 /**
  * Finds an Entity by its identifier.
  *
  * @param string $entityName
  * @param mixed $id
  * @param integer $lockMode
  * @param integer $lockVersion
  *
  * @return object
  */
 public function find($entityName, $id, $lockMode = LockMode::NONE, $lockVersion = null)
 {
     $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\'));
     if (is_object($id) && $this->metadataFactory->hasMetadataFor(ClassUtils::getClass($id))) {
         $id = $this->unitOfWork->getSingleIdentifierValue($id);
         if ($id === null) {
             throw ORMInvalidArgumentException::invalidIdentifierBindingEntity();
         }
     }
     if (!is_array($id)) {
         $id = array($class->identifier[0] => $id);
     }
     $sortedId = array();
     foreach ($class->identifier as $identifier) {
         if (!isset($id[$identifier])) {
             throw ORMException::missingIdentifierField($class->name, $identifier);
         }
         $sortedId[$identifier] = $id[$identifier];
     }
     $unitOfWork = $this->getUnitOfWork();
     // Check identity map first
     if (($entity = $unitOfWork->tryGetById($sortedId, $class->rootEntityName)) !== false) {
         if (!$entity instanceof $class->name) {
             return null;
         }
         switch ($lockMode) {
             case LockMode::OPTIMISTIC:
                 $this->lock($entity, $lockMode, $lockVersion);
                 break;
             case LockMode::PESSIMISTIC_READ:
             case LockMode::PESSIMISTIC_WRITE:
                 $persister = $unitOfWork->getEntityPersister($class->name);
                 $persister->refresh($sortedId, $entity, $lockMode);
                 break;
         }
         return $entity;
         // Hit!
     }
     $persister = $unitOfWork->getEntityPersister($class->name);
     switch ($lockMode) {
         case LockMode::NONE:
             return $persister->load($sortedId);
         case LockMode::OPTIMISTIC:
             if (!$class->isVersioned) {
                 throw OptimisticLockException::notVersioned($class->name);
             }
             $entity = $persister->load($sortedId);
             $unitOfWork->lock($entity, $lockMode, $lockVersion);
             return $entity;
         default:
             if (!$this->getConnection()->isTransactionActive()) {
                 throw TransactionRequiredException::transactionRequired();
             }
             return $persister->load($sortedId, null, null, array(), $lockMode);
     }
 }
开发者ID:relo-san,项目名称:doctrine2,代码行数:66,代码来源:EntityManager.php

示例2: toIdentifierArray

 /**
  * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata   The entity metadata.
  * @param mixed                               $identifier The entity identifier.
  *
  * @return array
  */
 private function toIdentifierArray(ClassMetadata $metadata, $identifier)
 {
     if (is_object($identifier) && $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($identifier))) {
         $identifier = $this->uow->getSingleIdentifierValue($identifier);
         if ($identifier === null) {
             throw ORMInvalidArgumentException::invalidIdentifierBindingEntity();
         }
     }
     return array($metadata->identifier[0] => $identifier);
 }
开发者ID:Dren-x,项目名称:mobitnew,代码行数:16,代码来源:DefaultCache.php


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