Skip to content

Commit

Permalink
Merge pull request #6731 from guiajlopes/master
Browse files Browse the repository at this point in the history
#6723 Remove  variable from UnitOfWork#createEntity()
  • Loading branch information
Ocramius committed Sep 26, 2017
2 parents 1d5c87e + a7e13f8 commit 53245e8
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,6 @@ private function newInstance($class)
public function createEntity($className, array $data, &$hints = [])
{
$class = $this->em->getClassMetadata($className);
//$isReadOnly = isset($hints[Query::HINT_READ_ONLY]);

$id = $this->identifierFlattener->flattenIdentifier($class, $data);
$idHash = implode(' ', $id);
Expand Down Expand Up @@ -2579,28 +2578,22 @@ public function createEntity($className, array $data, &$hints = [])
if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
$entity->__setInitialized(true);

$overrideLocalValues = true;

if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
} else {
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]);

// If only a specific entity is set to refresh, check that it's the one
if (isset($hints[Query::HINT_REFRESH_ENTITY])) {
$overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity;
if ( ! isset($hints[Query::HINT_REFRESH])
|| (isset($hints[Query::HINT_REFRESH_ENTITY]) && $hints[Query::HINT_REFRESH_ENTITY] !== $entity)) {
return $entity;
}
}

if ($overrideLocalValues) {
// inject ObjectManager upon refresh.
if ($entity instanceof ObjectManagerAware) {
$entity->injectObjectManager($this->em, $class);
}

$this->originalEntityData[$oid] = $data;
// inject ObjectManager upon refresh.
if ($entity instanceof ObjectManagerAware) {
$entity->injectObjectManager($this->em, $class);
}

$this->originalEntityData[$oid] = $data;
} else {
$entity = $this->newInstance($class);
$oid = spl_object_hash($entity);
Expand All @@ -2614,12 +2607,6 @@ public function createEntity($className, array $data, &$hints = [])
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}

$overrideLocalValues = true;
}

if ( ! $overrideLocalValues) {
return $entity;
}

foreach ($data as $field => $value) {
Expand Down Expand Up @@ -2823,10 +2810,8 @@ public function createEntity($className, array $data, &$hints = [])
}
}

if ($overrideLocalValues) {
// defer invoking of postLoad event to hydration complete step
$this->hydrationCompleteHandler->deferPostLoadInvoking($class, $entity);
}
// defer invoking of postLoad event to hydration complete step
$this->hydrationCompleteHandler->deferPostLoadInvoking($class, $entity);

return $entity;
}
Expand Down

0 comments on commit 53245e8

Please sign in to comment.