private function createInitializer(BaseClassMetadata $classMetadata, Hydrator $hydrator, \ReflectionProperty $reflectionId)
{
if ($classMetadata->getReflectionClass()->hasMethod('__wakeup')) {
return function (BaseProxy $proxy) use($reflectionId, $hydrator) {
$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);
$loaded = $hydrator->load(array($rid));
if (null === $loaded) {
throw DocumentNotFoundException::documentNotFound(get_class($proxy), $rid);
} else {
$hydrator->hydrate($loaded[0], $proxy);
}
};
}
return function (BaseProxy $proxy) use($reflectionId, $hydrator) {
$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);
$loaded = $hydrator->load(array($rid));
if (null === $loaded) {
throw DocumentNotFoundException::documentNotFound(get_class($proxy), $rid);
} else {
$hydrator->hydrate($loaded[0], $proxy);
}
};
}