/** * Generates a closure capable of finalizing a cloned proxy * * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata * @param \Doctrine\ODM\MongoDB\Persisters\DocumentPersister $documentPersister * @param \ReflectionProperty $reflectionId * * @return \Closure * * @throws \Doctrine\ODM\MongoDB\DocumentNotFoundException */ private function createCloner(BaseClassMetadata $classMetadata, DocumentPersister $documentPersister, ReflectionProperty $reflectionId) { return function (BaseProxy $proxy) use($documentPersister, $classMetadata, $reflectionId) { if ($proxy->__isInitialized()) { return; } $proxy->__setInitialized(true); $proxy->__setInitializer(null); $id = $reflectionId->getValue($proxy); $original = $documentPersister->load(array('_id' => $id)); if (null === $original) { throw DocumentNotFoundException::documentNotFound(get_class($proxy), $id); } foreach ($classMetadata->getReflectionClass()->getProperties() as $reflectionProperty) { $propertyName = $reflectionProperty->getName(); if ($classMetadata->hasField($propertyName) || $classMetadata->hasAssociation($propertyName)) { $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($proxy, $reflectionProperty->getValue($original)); } } }; }
private function query(array $query, array $newObj) { $query = $this->persister->prepareQueryOrNewObj($query); $result = $this->collection->update($query, $newObj, array('multiple' => true)); return $result; }