Reduce code duplication in ProxyFactory::createInitialized
The only difference between the ~30 lines in the IF-statement is that the __wakup method is called on the proxy object.
This commit is contained in:
parent
3c3b7364ba
commit
4df7699ced
1 changed files with 7 additions and 39 deletions
|
@ -123,45 +123,9 @@ class ProxyFactory extends AbstractProxyFactory
|
||||||
*/
|
*/
|
||||||
private function createInitializer(ClassMetadata $classMetadata, EntityPersister $entityPersister)
|
private function createInitializer(ClassMetadata $classMetadata, EntityPersister $entityPersister)
|
||||||
{
|
{
|
||||||
if ($classMetadata->getReflectionClass()->hasMethod('__wakeup')) {
|
$wakeupProxy = $classMetadata->getReflectionClass()->hasMethod('__wakeup');
|
||||||
return function (BaseProxy $proxy) use ($entityPersister, $classMetadata) {
|
|
||||||
$initializer = $proxy->__getInitializer();
|
|
||||||
$cloner = $proxy->__getCloner();
|
|
||||||
|
|
||||||
$proxy->__setInitializer(null);
|
return function (BaseProxy $proxy) use ($entityPersister, $classMetadata, $wakeupProxy) {
|
||||||
$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();
|
|
||||||
|
|
||||||
$identifier = $classMetadata->getIdentifierValues($proxy);
|
|
||||||
|
|
||||||
if (null === $entityPersister->loadById($identifier, $proxy)) {
|
|
||||||
$proxy->__setInitializer($initializer);
|
|
||||||
$proxy->__setCloner($cloner);
|
|
||||||
$proxy->__setInitialized(false);
|
|
||||||
|
|
||||||
throw EntityNotFoundException::fromClassNameAndIdentifier(
|
|
||||||
$classMetadata->getName(),
|
|
||||||
$this->identifierFlattener->flattenIdentifier($classMetadata, $identifier)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return function (BaseProxy $proxy) use ($entityPersister, $classMetadata) {
|
|
||||||
$initializer = $proxy->__getInitializer();
|
$initializer = $proxy->__getInitializer();
|
||||||
$cloner = $proxy->__getCloner();
|
$cloner = $proxy->__getCloner();
|
||||||
|
|
||||||
|
@ -175,13 +139,17 @@ class ProxyFactory extends AbstractProxyFactory
|
||||||
$properties = $proxy->__getLazyProperties();
|
$properties = $proxy->__getLazyProperties();
|
||||||
|
|
||||||
foreach ($properties as $propertyName => $property) {
|
foreach ($properties as $propertyName => $property) {
|
||||||
if (!isset($proxy->$propertyName)) {
|
if ( ! isset($proxy->$propertyName)) {
|
||||||
$proxy->$propertyName = $properties[$propertyName];
|
$proxy->$propertyName = $properties[$propertyName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$proxy->__setInitialized(true);
|
$proxy->__setInitialized(true);
|
||||||
|
|
||||||
|
if ($wakeupProxy) {
|
||||||
|
$proxy->__wakeup();
|
||||||
|
}
|
||||||
|
|
||||||
$identifier = $classMetadata->getIdentifierValues($proxy);
|
$identifier = $classMetadata->getIdentifierValues($proxy);
|
||||||
|
|
||||||
if (null === $entityPersister->loadById($identifier, $proxy)) {
|
if (null === $entityPersister->loadById($identifier, $proxy)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue