/** @private */ public function __load() { if (!$this->__isInitialized__ && $this->__documentPersister__) { $this->__isInitialized__ = true; if (method_exists($this, "__wakeup")) { // call this after __isInitialized__to avoid infinite recursion // but before loading to emulate what ClassMetadata::newInstance() // provides. $this->__wakeup(); } if ($this->__documentPersister__->load($this->__identifier__, $this) === null) { throw \Doctrine\ODM\MongoDB\DocumentNotFoundException::documentNotFound(get_class($this), $this->__identifier__); } unset($this->__documentPersister__, $this->__identifier__); } }
/** * 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)); } } }; }