Пример #1
0
 /**
  * Creates a closure capable of finalizing state a cloned proxy
  *
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata
  * @param \Doctrine\ORM\Persisters\Entity\EntityPersister    $entityPersister
  *
  * @return \Closure
  *
  * @throws \Doctrine\ORM\EntityNotFoundException
  */
 private function createCloner(ClassMetadata $classMetadata, EntityPersister $entityPersister)
 {
     return function (BaseProxy $proxy) use($entityPersister, $classMetadata) {
         if ($proxy->__isInitialized()) {
             return;
         }
         $proxy->__setInitialized(true);
         $proxy->__setInitializer(null);
         $class = $entityPersister->getClassMetadata();
         $identifier = $classMetadata->getIdentifierValues($proxy);
         $original = $entityPersister->loadById($identifier);
         if (null === $original) {
             throw EntityNotFoundException::fromClassNameAndIdentifier($classMetadata->getName(), $this->identifierFlattener->flattenIdentifier($classMetadata, $identifier));
         }
         foreach ($class->getReflectionClass()->getProperties() as $property) {
             if (!$class->hasField($property->name) && !$class->hasAssociation($property->name)) {
                 continue;
             }
             $property->setAccessible(true);
             $property->setValue($proxy, $property->getValue($original));
         }
     };
 }
 /**
  * {@inheritdoc}
  */
 public function getClassMetadata()
 {
     return $this->persister->getClassMetadata();
 }
 /**
  * Modified version of BasicEntityPersister::prepareUpdateData()
  * git revision d9fc5388f1aa1751a0e148e76b4569bd207338e9 (v2.5.3)
  *
  * @license MIT
  *
  * @author  Roman Borschel <*****@*****.**>
  * @author  Giorgio Sironi <*****@*****.**>
  * @author  Benjamin Eberlei <*****@*****.**>
  * @author  Alexander <*****@*****.**>
  * @author  Fabio B. Silva <*****@*****.**>
  * @author  Rob Caiger <*****@*****.**>
  * @author  Simon Mönch <*****@*****.**>
  *
  * @param EntityPersister|BasicEntityPersister $persister
  * @param                 $entity
  *
  * @return array
  */
 private function prepareUpdateData($persister, $entity)
 {
     $uow = $this->em->getUnitOfWork();
     $classMetadata = $persister->getClassMetadata();
     $versionField = null;
     $result = array();
     if (($versioned = $classMetadata->isVersioned) != false) {
         $versionField = $classMetadata->versionField;
     }
     foreach ($uow->getEntityChangeSet($entity) as $field => $change) {
         if (isset($versionField) && $versionField == $field) {
             continue;
         }
         if (isset($classMetadata->embeddedClasses[$field])) {
             continue;
         }
         $newVal = $change[1];
         if (!isset($classMetadata->associationMappings[$field])) {
             $columnName = $classMetadata->columnNames[$field];
             $result[$persister->getOwningTable($field)][$columnName] = $newVal;
             continue;
         }
         $assoc = $classMetadata->associationMappings[$field];
         // Only owning side of x-1 associations can have a FK column.
         if (!$assoc['isOwningSide'] || !($assoc['type'] & ClassMetadata::TO_ONE)) {
             continue;
         }
         if ($newVal !== null) {
             if ($uow->isScheduledForInsert($newVal)) {
                 $newVal = null;
             }
         }
         $newValId = null;
         if ($newVal !== null) {
             if (!$uow->isInIdentityMap($newVal)) {
                 continue;
             }
             $newValId = $uow->getEntityIdentifier($newVal);
         }
         $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
         $owningTable = $persister->getOwningTable($field);
         foreach ($assoc['joinColumns'] as $joinColumn) {
             $sourceColumn = $joinColumn['name'];
             $targetColumn = $joinColumn['referencedColumnName'];
             $result[$owningTable][$sourceColumn] = $newValId ? $newValId[$targetClass->getFieldForColumn($targetColumn)] : null;
         }
     }
     return $result;
 }