private function createInitializer(BaseClassMetadata $classMetadata, DocumentPersister $documentPersister, ReflectionProperty $reflectionId)
{
if ($classMetadata->getReflectionClass()->hasMethod('__wakeup')) {
return function (BaseProxy $proxy) use($documentPersister, $reflectionId) {
$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();
$id = $reflectionId->getValue($proxy);
if (null === $documentPersister->load(array('_id' => $id), $proxy)) {
if (!$this->lifecycleEventManager->documentNotFound($proxy, $id)) {
throw DocumentNotFoundException::documentNotFound(get_class($proxy), $id);
}
}
if ($proxy instanceof NotifyPropertyChanged) {
$proxy->addPropertyChangedListener($this->uow);
}
};
}
return function (BaseProxy $proxy) use($documentPersister, $reflectionId) {
$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);
$id = $reflectionId->getValue($proxy);
if (null === $documentPersister->load(array('_id' => $id), $proxy)) {
if (!$this->lifecycleEventManager->documentNotFound($proxy, $id)) {
throw DocumentNotFoundException::documentNotFound(get_class($proxy), $id);
}
}
if ($proxy instanceof NotifyPropertyChanged) {
$proxy->addPropertyChangedListener($this->uow);
}
};
}