示例#1
0
 /**
  * Generates a closure capable of initializing a proxy
  *
  * @param ClassMetadata       $class
  * @param DocumentPersister   $documentPersister
  * @param \ReflectionProperty $reflectionId
  *
  * @return callable
  */
 private function createInitializer(ClassMetadata $class, DocumentPersister $documentPersister, \ReflectionProperty $reflectionId)
 {
     if ($class->getReflectionClass()->hasMethod('__wakeup')) {
         return function (BaseProxy $proxy) use($reflectionId, $documentPersister) {
             $proxy->__setInitializer(null);
             $proxy->__setCloner(null);
             if ($proxy->__isInitialized()) {
                 return;
             }
             $properties = $proxy->__getLazyProperties();
             foreach ($properties as $propertyName => $property) {
                 if (!isset($proxy->{$propertyName})) {
                     $proxy->{$propertyName} = $properties[$propertyName];
                 }
             }
             $proxy->__setInitialized(true);
             $proxy->__wakeup();
             $rid = $reflectionId->getValue($proxy);
             if ($documentPersister->load($rid, '*:0', $proxy) === null) {
                 throw DocumentNotFoundException::documentNotFound(get_class($proxy), $rid);
             }
         };
     }
     return function (BaseProxy $proxy) use($reflectionId, $documentPersister) {
         $proxy->__setInitializer(null);
         $proxy->__setCloner(null);
         if ($proxy->__isInitialized()) {
             return;
         }
         $properties = $proxy->__getLazyProperties();
         foreach ($properties as $propertyName => $property) {
             if (!isset($proxy->{$propertyName})) {
                 $proxy->{$propertyName} = $properties[$propertyName];
             }
         }
         $proxy->__setInitialized(true);
         $rid = $reflectionId->getValue($proxy);
         if ($documentPersister->load($rid, '*:0', $proxy) === null) {
             throw DocumentNotFoundException::documentNotFound(get_class($proxy), $rid);
         }
     };
 }
 function testGetReflectionClass()
 {
     $this->assertInstanceOf('\\ReflectionClass', $this->metadata->getReflectionClass());
 }