Skip to content

Commit

Permalink
Only override initialiser if proxy object isn't initialised yet
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Oct 8, 2019
1 parent f86dbc6 commit f54d694
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,18 @@ public function hydrate(object $document, array $data, array $hints = []) : arra
}
}

if ($document instanceof GhostObjectInterface) {
if ($document instanceof GhostObjectInterface && $document->getProxyInitializer() !== null) {
// Inject an empty initialiser to not load any object data
$document->setProxyInitializer(static function () {
$document->setProxyInitializer(static function (
GhostObjectInterface $ghostObject,
string $method, // we don't care
array $parameters, // we don't care
&$initializer,
array $properties // we currently do not use this
) : bool {
$initializer = null;
return true;
});
$document->initializeProxy();
$document->setProxyInitializer(null);
}

$data = $this->getHydratorFor($metadata->name)->hydrate($document, $data, $hints);
Expand Down

0 comments on commit f54d694

Please sign in to comment.