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


PHP ORMInvalidArgumentException::entityIsRemoved方法代码示例

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


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

示例1: doMerge

 /**
  * Executes a merge operation on an entity.
  *
  * @param object      $entity
  * @param array       $visited
  * @param object|null $prevManagedCopy
  * @param array|null  $assoc
  *
  * @return object The managed copy of the entity.
  *
  * @throws OptimisticLockException If the entity uses optimistic locking through a version
  *         attribute and the version check against the managed copy fails.
  * @throws ORMInvalidArgumentException If the entity instance is NEW.
  * @throws EntityNotFoundException
  */
 private function doMerge($entity, array &$visited, $prevManagedCopy = null, $assoc = null)
 {
     $oid = spl_object_hash($entity);
     if (isset($visited[$oid])) {
         return $visited[$oid];
         // Prevent infinite recursion
     }
     $visited[$oid] = $entity;
     // mark visited
     $class = $this->em->getClassMetadata(get_class($entity));
     // First we assume DETACHED, although it can still be NEW but we can avoid
     // an extra db-roundtrip this way. If it is not MANAGED but has an identity,
     // we need to fetch it from the db anyway in order to merge.
     // MANAGED entities are ignored by the merge operation.
     $managedCopy = $entity;
     if ($this->getEntityState($entity, self::STATE_DETACHED) !== self::STATE_MANAGED) {
         if ($entity instanceof Proxy && !$entity->__isInitialized()) {
             $this->em->getProxyFactory()->resetUninitializedProxy($entity);
             $entity->__load();
         }
         // Try to look the entity up in the identity map.
         $id = $class->getIdentifierValues($entity);
         // If there is no ID, it is actually NEW.
         if (!$id) {
             $managedCopy = $this->newInstance($class);
             $this->persistNew($class, $managedCopy);
         } else {
             $flatId = $class->containsForeignIdentifier ? $this->flattenIdentifier($class, $id) : $id;
             $managedCopy = $this->tryGetById($flatId, $class->rootEntityName);
             if ($managedCopy) {
                 // We have the entity in-memory already, just make sure its not removed.
                 if ($this->getEntityState($managedCopy) == self::STATE_REMOVED) {
                     throw ORMInvalidArgumentException::entityIsRemoved($managedCopy, "merge");
                 }
             } else {
                 // We need to fetch the managed copy in order to merge.
                 $managedCopy = $this->em->find($class->name, $flatId);
             }
             if ($managedCopy === null) {
                 // If the identifier is ASSIGNED, it is NEW, otherwise an error
                 // since the managed entity was not found.
                 if (!$class->isIdentifierNatural()) {
                     throw new EntityNotFoundException($class->getName());
                 }
                 $managedCopy = $this->newInstance($class);
                 $class->setIdentifierValues($managedCopy, $id);
                 $this->persistNew($class, $managedCopy);
             } else {
                 if ($managedCopy instanceof Proxy && !$managedCopy->__isInitialized__) {
                     $managedCopy->__load();
                 }
             }
         }
         if ($class->isVersioned) {
             $reflField = $class->reflFields[$class->versionField];
             $managedCopyVersion = $reflField->getValue($managedCopy);
             $entityVersion = $reflField->getValue($entity);
             // Throw exception if versions don't match.
             if ($managedCopyVersion != $entityVersion) {
                 throw OptimisticLockException::lockFailedVersionMismatch($entity, $entityVersion, $managedCopyVersion);
             }
         }
         // Merge state of $entity into existing (managed) entity
         foreach ($class->reflClass->getProperties() as $prop) {
             $name = $prop->name;
             $prop->setAccessible(true);
             if (!isset($class->associationMappings[$name])) {
                 if (!$class->isIdentifier($name)) {
                     $prop->setValue($managedCopy, $prop->getValue($entity));
                 }
             } else {
                 $assoc2 = $class->associationMappings[$name];
                 if ($assoc2['type'] & ClassMetadata::TO_ONE) {
                     $other = $prop->getValue($entity);
                     if ($other === null) {
                         $prop->setValue($managedCopy, null);
                     } else {
                         if ($other instanceof Proxy && !$other->__isInitialized__) {
                             // do not merge fields marked lazy that have not been fetched.
                             continue;
                         } else {
                             if (!$assoc2['isCascadeMerge']) {
                                 if ($this->getEntityState($other) === self::STATE_DETACHED) {
                                     $targetClass = $this->em->getClassMetadata($assoc2['targetEntity']);
                                     $relatedId = $targetClass->getIdentifierValues($other);
//.........这里部分代码省略.........
开发者ID:josercl,项目名称:forum,代码行数:101,代码来源:UnitOfWork.php

示例2: doMerge

 /**
  * Executes a merge operation on an entity.
  *
  * @param object      $entity
  * @param array       $visited
  * @param object|null $prevManagedCopy
  * @param array|null  $assoc
  *
  * @return object The managed copy of the entity.
  *
  * @throws OptimisticLockException If the entity uses optimistic locking through a version
  *         attribute and the version check against the managed copy fails.
  * @throws ORMInvalidArgumentException If the entity instance is NEW.
  * @throws EntityNotFoundException
  */
 private function doMerge($entity, array &$visited, $prevManagedCopy = null, $assoc = null)
 {
     $oid = spl_object_hash($entity);
     if (isset($visited[$oid])) {
         $managedCopy = $visited[$oid];
         if ($prevManagedCopy !== null) {
             $this->updateAssociationWithMergedEntity($entity, $assoc, $prevManagedCopy, $managedCopy);
         }
         return $managedCopy;
     }
     $class = $this->em->getClassMetadata(get_class($entity));
     // First we assume DETACHED, although it can still be NEW but we can avoid
     // an extra db-roundtrip this way. If it is not MANAGED but has an identity,
     // we need to fetch it from the db anyway in order to merge.
     // MANAGED entities are ignored by the merge operation.
     $managedCopy = $entity;
     if ($this->getEntityState($entity, self::STATE_DETACHED) !== self::STATE_MANAGED) {
         // Try to look the entity up in the identity map.
         $id = $class->getIdentifierValues($entity);
         // If there is no ID, it is actually NEW.
         if (!$id) {
             $managedCopy = $this->newInstance($class);
             $this->persistNew($class, $managedCopy);
         } else {
             $flatId = $class->containsForeignIdentifier ? $this->identifierFlattener->flattenIdentifier($class, $id) : $id;
             $managedCopy = $this->tryGetById($flatId, $class->rootEntityName);
             if ($managedCopy) {
                 // We have the entity in-memory already, just make sure its not removed.
                 if ($this->getEntityState($managedCopy) == self::STATE_REMOVED) {
                     throw ORMInvalidArgumentException::entityIsRemoved($managedCopy, "merge");
                 }
             } else {
                 // We need to fetch the managed copy in order to merge.
                 $managedCopy = $this->em->find($class->name, $flatId);
             }
             if ($managedCopy === null) {
                 // If the identifier is ASSIGNED, it is NEW, otherwise an error
                 // since the managed entity was not found.
                 if (!$class->isIdentifierNatural()) {
                     throw EntityNotFoundException::fromClassNameAndIdentifier($class->getName(), $this->identifierFlattener->flattenIdentifier($class, $id));
                 }
                 $managedCopy = $this->newInstance($class);
                 $class->setIdentifierValues($managedCopy, $id);
                 $this->persistNew($class, $managedCopy);
             }
         }
         if ($class->isVersioned) {
             $reflField = $class->reflFields[$class->versionField];
             $managedCopyVersion = $reflField->getValue($managedCopy);
             $entityVersion = $reflField->getValue($entity);
             // Throw exception if versions don't match.
             if ($managedCopyVersion != $entityVersion) {
                 throw OptimisticLockException::lockFailedVersionMismatch($entity, $entityVersion, $managedCopyVersion);
             }
         }
         $visited[$oid] = $managedCopy;
         // mark visited
         if (!($entity instanceof Proxy && !$entity->__isInitialized())) {
             if ($managedCopy instanceof Proxy && !$managedCopy->__isInitialized()) {
                 $managedCopy->__load();
             }
             $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy);
         }
         if ($class->isChangeTrackingDeferredExplicit()) {
             $this->scheduleForDirtyCheck($entity);
         }
     }
     if ($prevManagedCopy !== null) {
         $this->updateAssociationWithMergedEntity($entity, $assoc, $prevManagedCopy, $managedCopy);
     }
     // Mark the managed copy visited as well
     $visited[spl_object_hash($managedCopy)] = $managedCopy;
     $this->cascadeMerge($entity, $managedCopy, $visited);
     return $managedCopy;
 }
开发者ID:SylvainSimon,项目名称:Metinify,代码行数:90,代码来源:UnitOfWork.php


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