1
0
mirror of synced 2025-02-09 08:49:26 +03:00

Merge pull request #6731 from guiajlopes/master

#6723 Remove  variable from UnitOfWork#createEntity()
This commit is contained in:
Marco Pivetta 2017-09-26 13:10:39 +02:00 committed by GitHub
commit 53245e8a73

View File

@ -2549,7 +2549,6 @@ class UnitOfWork implements PropertyChangedListener
public function createEntity($className, array $data, &$hints = []) public function createEntity($className, array $data, &$hints = [])
{ {
$class = $this->em->getClassMetadata($className); $class = $this->em->getClassMetadata($className);
//$isReadOnly = isset($hints[Query::HINT_READ_ONLY]);
$id = $this->identifierFlattener->flattenIdentifier($class, $data); $id = $this->identifierFlattener->flattenIdentifier($class, $data);
$idHash = implode(' ', $id); $idHash = implode(' ', $id);
@ -2579,28 +2578,22 @@ class UnitOfWork implements PropertyChangedListener
if ($entity instanceof Proxy && ! $entity->__isInitialized()) { if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
$entity->__setInitialized(true); $entity->__setInitialized(true);
$overrideLocalValues = true;
if ($entity instanceof NotifyPropertyChanged) { if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this); $entity->addPropertyChangedListener($this);
} }
} else { } else {
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]); if ( ! isset($hints[Query::HINT_REFRESH])
|| (isset($hints[Query::HINT_REFRESH_ENTITY]) && $hints[Query::HINT_REFRESH_ENTITY] !== $entity)) {
// If only a specific entity is set to refresh, check that it's the one return $entity;
if (isset($hints[Query::HINT_REFRESH_ENTITY])) {
$overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity;
} }
} }
if ($overrideLocalValues) { // inject ObjectManager upon refresh.
// inject ObjectManager upon refresh. if ($entity instanceof ObjectManagerAware) {
if ($entity instanceof ObjectManagerAware) { $entity->injectObjectManager($this->em, $class);
$entity->injectObjectManager($this->em, $class);
}
$this->originalEntityData[$oid] = $data;
} }
$this->originalEntityData[$oid] = $data;
} else { } else {
$entity = $this->newInstance($class); $entity = $this->newInstance($class);
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
@ -2614,12 +2607,6 @@ class UnitOfWork implements PropertyChangedListener
if ($entity instanceof NotifyPropertyChanged) { if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this); $entity->addPropertyChangedListener($this);
} }
$overrideLocalValues = true;
}
if ( ! $overrideLocalValues) {
return $entity;
} }
foreach ($data as $field => $value) { foreach ($data as $field => $value) {
@ -2823,10 +2810,8 @@ class UnitOfWork implements PropertyChangedListener
} }
} }
if ($overrideLocalValues) { // defer invoking of postLoad event to hydration complete step
// defer invoking of postLoad event to hydration complete step $this->hydrationCompleteHandler->deferPostLoadInvoking($class, $entity);
$this->hydrationCompleteHandler->deferPostLoadInvoking($class, $entity);
}
return $entity; return $entity;
} }