Ejemplo n.º 1
0
 /**
  * Creates a closure capable of finalizing state a cloned proxy
  *
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata
  * @param \Doctrine\ORM\Persisters\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();
         $original = $entityPersister->loadById($classMetadata->getIdentifierValues($proxy));
         if (null === $original) {
             throw new EntityNotFoundException();
         }
         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));
         }
     };
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function refresh(array $id, $entity, $lockMode = null)
 {
     $this->persister->refresh($id, $entity, $lockMode);
 }