/**
  * Creates a closure capable of initializing a proxy
  *
  * @param ApiMetadata  $classMetadata
  * @param ApiPersister $persister
  *
  * @return \Closure
  * @throws FetchException
  */
 private function createInitializer(ApiMetadata $classMetadata, ApiPersister $persister)
 {
     $wakeupProxy = $classMetadata->getReflectionClass()->hasMethod('__wakeup');
     return function (Proxy $proxy) use($classMetadata, $wakeupProxy, $persister) {
         $initializer = $proxy->__getInitializer();
         $cloner = $proxy->__getCloner();
         $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];
             }
         }
         $identifier = $classMetadata->getIdentifierValues($proxy);
         if (null === $persister->loadById($identifier, $proxy)) {
             $proxy->__setInitializer($initializer);
             $proxy->__setCloner($cloner);
             $proxy->__setInitialized(false);
             throw FetchException::notFound();
         }
         $proxy->__setInitialized(true);
         if ($wakeupProxy) {
             $proxy->__wakeup();
         }
     };
 }
 /**
  * Returns the class name of the object managed by the repository.
  *
  * @return string
  */
 public function getClassName()
 {
     return $this->metadata->getReflectionClass()->getName();
 }