vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 155

Open in your IDE?
  1. <?php
  2. /*
  3.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  *
  15.  * This software consists of voluntary contributions made by many individuals
  16.  * and is licensed under the MIT license. For more information, see
  17.  * <http://www.doctrine-project.org>.
  18.  */
  19. namespace Doctrine\ORM\Internal\Hydration;
  20. use Doctrine\Common\Collections\ArrayCollection;
  21. use Doctrine\Common\Proxy\Proxy;
  22. use Doctrine\ORM\Mapping\ClassMetadata;
  23. use Doctrine\ORM\PersistentCollection;
  24. use Doctrine\ORM\Query;
  25. use Doctrine\ORM\UnitOfWork;
  26. use PDO;
  27. use function array_fill_keys;
  28. use function array_keys;
  29. use function count;
  30. use function is_array;
  31. use function key;
  32. use function ltrim;
  33. use function spl_object_hash;
  34. /**
  35.  * The ObjectHydrator constructs an object graph out of an SQL result set.
  36.  *
  37.  * Internal note: Highly performance-sensitive code.
  38.  */
  39. class ObjectHydrator extends AbstractHydrator
  40. {
  41.     /** @var mixed[] */
  42.     private $identifierMap = [];
  43.     /** @var mixed[] */
  44.     private $resultPointers = [];
  45.     /** @var mixed[] */
  46.     private $idTemplate = [];
  47.     /** @var int */
  48.     private $resultCounter 0;
  49.     /** @var mixed[] */
  50.     private $rootAliases = [];
  51.     /** @var mixed[] */
  52.     private $initializedCollections = [];
  53.     /** @var mixed[] */
  54.     private $existingCollections = [];
  55.     /**
  56.      * {@inheritdoc}
  57.      */
  58.     protected function prepare()
  59.     {
  60.         if (! isset($this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD])) {
  61.             $this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD] = true;
  62.         }
  63.         foreach ($this->_rsm->aliasMap as $dqlAlias => $className) {
  64.             $this->identifierMap[$dqlAlias] = [];
  65.             $this->idTemplate[$dqlAlias]    = '';
  66.             // Remember which associations are "fetch joined", so that we know where to inject
  67.             // collection stubs or proxies and where not.
  68.             if (! isset($this->_rsm->relationMap[$dqlAlias])) {
  69.                 continue;
  70.             }
  71.             $parent $this->_rsm->parentAliasMap[$dqlAlias];
  72.             if (! isset($this->_rsm->aliasMap[$parent])) {
  73.                 throw HydrationException::parentObjectOfRelationNotFound($dqlAlias$parent);
  74.             }
  75.             $sourceClassName $this->_rsm->aliasMap[$parent];
  76.             $sourceClass     $this->getClassMetadata($sourceClassName);
  77.             $assoc           $sourceClass->associationMappings[$this->_rsm->relationMap[$dqlAlias]];
  78.             $this->_hints['fetched'][$parent][$assoc['fieldName']] = true;
  79.             if ($assoc['type'] === ClassMetadata::MANY_TO_MANY) {
  80.                 continue;
  81.             }
  82.             // Mark any non-collection opposite sides as fetched, too.
  83.             if ($assoc['mappedBy']) {
  84.                 $this->_hints['fetched'][$dqlAlias][$assoc['mappedBy']] = true;
  85.                 continue;
  86.             }
  87.             // handle fetch-joined owning side bi-directional one-to-one associations
  88.             if ($assoc['inversedBy']) {
  89.                 $class        $this->getClassMetadata($className);
  90.                 $inverseAssoc $class->associationMappings[$assoc['inversedBy']];
  91.                 if (! ($inverseAssoc['type'] & ClassMetadata::TO_ONE)) {
  92.                     continue;
  93.                 }
  94.                 $this->_hints['fetched'][$dqlAlias][$inverseAssoc['fieldName']] = true;
  95.             }
  96.         }
  97.     }
  98.     /**
  99.      * {@inheritdoc}
  100.      */
  101.     protected function cleanup()
  102.     {
  103.         $eagerLoad = isset($this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD]) && $this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD] === true;
  104.         parent::cleanup();
  105.         $this->identifierMap          =
  106.         $this->initializedCollections =
  107.         $this->existingCollections    =
  108.         $this->resultPointers         = [];
  109.         if ($eagerLoad) {
  110.             $this->_uow->triggerEagerLoads();
  111.         }
  112.         $this->_uow->hydrationComplete();
  113.     }
  114.     protected function cleanupAfterRowIteration(): void
  115.     {
  116.         $this->identifierMap          =
  117.         $this->initializedCollections =
  118.         $this->existingCollections    =
  119.         $this->resultPointers         = [];
  120.     }
  121.     /**
  122.      * {@inheritdoc}
  123.      */
  124.     protected function hydrateAllData()
  125.     {
  126.         $result = [];
  127.         while ($row $this->_stmt->fetch(PDO::FETCH_ASSOC)) {
  128.             $this->hydrateRowData($row$result);
  129.         }
  130.         // Take snapshots from all newly initialized collections
  131.         foreach ($this->initializedCollections as $coll) {
  132.             $coll->takeSnapshot();
  133.         }
  134.         return $result;
  135.     }
  136.     /**
  137.      * Initializes a related collection.
  138.      *
  139.      * @param object $entity         The entity to which the collection belongs.
  140.      * @param string $fieldName      The name of the field on the entity that holds the collection.
  141.      * @param string $parentDqlAlias Alias of the parent fetch joining this collection.
  142.      */
  143.     private function initRelatedCollection(
  144.         $entity,
  145.         ClassMetadata $class,
  146.         string $fieldName,
  147.         string $parentDqlAlias
  148.     ): PersistentCollection {
  149.         $oid      spl_object_hash($entity);
  150.         $relation $class->associationMappings[$fieldName];
  151.         $value    $class->reflFields[$fieldName]->getValue($entity);
  152.         if ($value === null || is_array($value)) {
  153.             $value = new ArrayCollection((array) $value);
  154.         }
  155.         if (! $value instanceof PersistentCollection) {
  156.             $value = new PersistentCollection(
  157.                 $this->_em,
  158.                 $this->_metadataCache[$relation['targetEntity']],
  159.                 $value
  160.             );
  161.             $value->setOwner($entity$relation);
  162.             $class->reflFields[$fieldName]->setValue($entity$value);
  163.             $this->_uow->setOriginalEntityProperty($oid$fieldName$value);
  164.             $this->initializedCollections[$oid $fieldName] = $value;
  165.         } elseif (
  166.             isset($this->_hints[Query::HINT_REFRESH]) ||
  167.             isset($this->_hints['fetched'][$parentDqlAlias][$fieldName]) &&
  168.              ! $value->isInitialized()
  169.         ) {
  170.             // Is already PersistentCollection, but either REFRESH or FETCH-JOIN and UNINITIALIZED!
  171.             $value->setDirty(false);
  172.             $value->setInitialized(true);
  173.             $value->unwrap()->clear();
  174.             $this->initializedCollections[$oid $fieldName] = $value;
  175.         } else {
  176.             // Is already PersistentCollection, and DON'T REFRESH or FETCH-JOIN!
  177.             $this->existingCollections[$oid $fieldName] = $value;
  178.         }
  179.         return $value;
  180.     }
  181.     /**
  182.      * Gets an entity instance.
  183.      *
  184.      * @param string $dqlAlias The DQL alias of the entity's class.
  185.      * @psalm-param array<string, mixed> $data     The instance data.
  186.      *
  187.      * @return object
  188.      *
  189.      * @throws HydrationException
  190.      */
  191.     private function getEntity(array $datastring $dqlAlias)
  192.     {
  193.         $className $this->_rsm->aliasMap[$dqlAlias];
  194.         if (isset($this->_rsm->discriminatorColumns[$dqlAlias])) {
  195.             $fieldName $this->_rsm->discriminatorColumns[$dqlAlias];
  196.             if (! isset($this->_rsm->metaMappings[$fieldName])) {
  197.                 throw HydrationException::missingDiscriminatorMetaMappingColumn($className$fieldName$dqlAlias);
  198.             }
  199.             $discrColumn $this->_rsm->metaMappings[$fieldName];
  200.             if (! isset($data[$discrColumn])) {
  201.                 throw HydrationException::missingDiscriminatorColumn($className$discrColumn$dqlAlias);
  202.             }
  203.             if ($data[$discrColumn] === '') {
  204.                 throw HydrationException::emptyDiscriminatorValue($dqlAlias);
  205.             }
  206.             $discrMap           $this->_metadataCache[$className]->discriminatorMap;
  207.             $discriminatorValue = (string) $data[$discrColumn];
  208.             if (! isset($discrMap[$discriminatorValue])) {
  209.                 throw HydrationException::invalidDiscriminatorValue($discriminatorValuearray_keys($discrMap));
  210.             }
  211.             $className $discrMap[$discriminatorValue];
  212.             unset($data[$discrColumn]);
  213.         }
  214.         if (isset($this->_hints[Query::HINT_REFRESH_ENTITY]) && isset($this->rootAliases[$dqlAlias])) {
  215.             $this->registerManaged($this->_metadataCache[$className], $this->_hints[Query::HINT_REFRESH_ENTITY], $data);
  216.         }
  217.         $this->_hints['fetchAlias'] = $dqlAlias;
  218.         return $this->_uow->createEntity($className$data$this->_hints);
  219.     }
  220.     /**
  221.      * @psalm-param class-string $className
  222.      * @psalm-param array<string, mixed> $data
  223.      *
  224.      * @return mixed
  225.      */
  226.     private function getEntityFromIdentityMap(string $className, array $data)
  227.     {
  228.         // TODO: Abstract this code and UnitOfWork::createEntity() equivalent?
  229.         $class $this->_metadataCache[$className];
  230.         if ($class->isIdentifierComposite) {
  231.             $idHash '';
  232.             foreach ($class->identifier as $fieldName) {
  233.                 $idHash .= ' ' . (isset($class->associationMappings[$fieldName])
  234.                     ? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']]
  235.                     : $data[$fieldName]);
  236.             }
  237.             return $this->_uow->tryGetByIdHash(ltrim($idHash), $class->rootEntityName);
  238.         } elseif (isset($class->associationMappings[$class->identifier[0]])) {
  239.             return $this->_uow->tryGetByIdHash($data[$class->associationMappings[$class->identifier[0]]['joinColumns'][0]['name']], $class->rootEntityName);
  240.         }
  241.         return $this->_uow->tryGetByIdHash($data[$class->identifier[0]], $class->rootEntityName);
  242.     }
  243.     /**
  244.      * Hydrates a single row in an SQL result set.
  245.      *
  246.      * @internal
  247.      * First, the data of the row is split into chunks where each chunk contains data
  248.      * that belongs to a particular component/class. Afterwards, all these chunks
  249.      * are processed, one after the other. For each chunk of class data only one of the
  250.      * following code paths is executed:
  251.      *
  252.      * Path A: The data chunk belongs to a joined/associated object and the association
  253.      *         is collection-valued.
  254.      * Path B: The data chunk belongs to a joined/associated object and the association
  255.      *         is single-valued.
  256.      * Path C: The data chunk belongs to a root result element/object that appears in the topmost
  257.      *         level of the hydrated result. A typical example are the objects of the type
  258.      *         specified by the FROM clause in a DQL query.
  259.      *
  260.      * @param mixed[] $row    The data of the row to process.
  261.      * @param mixed[] $result The result array to fill.
  262.      *
  263.      * @return void
  264.      */
  265.     protected function hydrateRowData(array $row, array &$result)
  266.     {
  267.         // Initialize
  268.         $id                 $this->idTemplate// initialize the id-memory
  269.         $nonemptyComponents = [];
  270.         // Split the row data into chunks of class data.
  271.         $rowData $this->gatherRowData($row$id$nonemptyComponents);
  272.         // reset result pointers for each data row
  273.         $this->resultPointers = [];
  274.         // Hydrate the data chunks
  275.         foreach ($rowData['data'] as $dqlAlias => $data) {
  276.             $entityName $this->_rsm->aliasMap[$dqlAlias];
  277.             if (isset($this->_rsm->parentAliasMap[$dqlAlias])) {
  278.                 // It's a joined result
  279.                 $parentAlias $this->_rsm->parentAliasMap[$dqlAlias];
  280.                 // we need the $path to save into the identifier map which entities were already
  281.                 // seen for this parent-child relationship
  282.                 $path $parentAlias '.' $dqlAlias;
  283.                 // We have a RIGHT JOIN result here. Doctrine cannot hydrate RIGHT JOIN Object-Graphs
  284.                 if (! isset($nonemptyComponents[$parentAlias])) {
  285.                     // TODO: Add special case code where we hydrate the right join objects into identity map at least
  286.                     continue;
  287.                 }
  288.                 $parentClass   $this->_metadataCache[$this->_rsm->aliasMap[$parentAlias]];
  289.                 $relationField $this->_rsm->relationMap[$dqlAlias];
  290.                 $relation      $parentClass->associationMappings[$relationField];
  291.                 $reflField     $parentClass->reflFields[$relationField];
  292.                 // Get a reference to the parent object to which the joined element belongs.
  293.                 if ($this->_rsm->isMixed && isset($this->rootAliases[$parentAlias])) {
  294.                     $objectClass  $this->resultPointers[$parentAlias];
  295.                     $parentObject $objectClass[key($objectClass)];
  296.                 } elseif (isset($this->resultPointers[$parentAlias])) {
  297.                     $parentObject $this->resultPointers[$parentAlias];
  298.                 } else {
  299.                     // Parent object of relation not found, mark as not-fetched again
  300.                     $element $this->getEntity($data$dqlAlias);
  301.                     // Update result pointer and provide initial fetch data for parent
  302.                     $this->resultPointers[$dqlAlias]               = $element;
  303.                     $rowData['data'][$parentAlias][$relationField] = $element;
  304.                     // Mark as not-fetched again
  305.                     unset($this->_hints['fetched'][$parentAlias][$relationField]);
  306.                     continue;
  307.                 }
  308.                 $oid spl_object_hash($parentObject);
  309.                 // Check the type of the relation (many or single-valued)
  310.                 if (! ($relation['type'] & ClassMetadata::TO_ONE)) {
  311.                     // PATH A: Collection-valued association
  312.                     $reflFieldValue $reflField->getValue($parentObject);
  313.                     if (isset($nonemptyComponents[$dqlAlias])) {
  314.                         $collKey $oid $relationField;
  315.                         if (isset($this->initializedCollections[$collKey])) {
  316.                             $reflFieldValue $this->initializedCollections[$collKey];
  317.                         } elseif (! isset($this->existingCollections[$collKey])) {
  318.                             $reflFieldValue $this->initRelatedCollection($parentObject$parentClass$relationField$parentAlias);
  319.                         }
  320.                         $indexExists  = isset($this->identifierMap[$path][$id[$parentAlias]][$id[$dqlAlias]]);
  321.                         $index        $indexExists $this->identifierMap[$path][$id[$parentAlias]][$id[$dqlAlias]] : false;
  322.                         $indexIsValid $index !== false ? isset($reflFieldValue[$index]) : false;
  323.                         if (! $indexExists || ! $indexIsValid) {
  324.                             if (isset($this->existingCollections[$collKey])) {
  325.                                 // Collection exists, only look for the element in the identity map.
  326.                                 $element $this->getEntityFromIdentityMap($entityName$data);
  327.                                 if ($element) {
  328.                                     $this->resultPointers[$dqlAlias] = $element;
  329.                                 } else {
  330.                                     unset($this->resultPointers[$dqlAlias]);
  331.                                 }
  332.                             } else {
  333.                                 $element $this->getEntity($data$dqlAlias);
  334.                                 if (isset($this->_rsm->indexByMap[$dqlAlias])) {
  335.                                     $indexValue $row[$this->_rsm->indexByMap[$dqlAlias]];
  336.                                     $reflFieldValue->hydrateSet($indexValue$element);
  337.                                     $this->identifierMap[$path][$id[$parentAlias]][$id[$dqlAlias]] = $indexValue;
  338.                                 } else {
  339.                                     $reflFieldValue->hydrateAdd($element);
  340.                                     $reflFieldValue->last();
  341.                                     $this->identifierMap[$path][$id[$parentAlias]][$id[$dqlAlias]] = $reflFieldValue->key();
  342.                                 }
  343.                                 // Update result pointer
  344.                                 $this->resultPointers[$dqlAlias] = $element;
  345.                             }
  346.                         } else {
  347.                             // Update result pointer
  348.                             $this->resultPointers[$dqlAlias] = $reflFieldValue[$index];
  349.                         }
  350.                     } elseif (! $reflFieldValue) {
  351.                         $this->initRelatedCollection($parentObject$parentClass$relationField$parentAlias);
  352.                     } elseif ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false) {
  353.                         $reflFieldValue->setInitialized(true);
  354.                     }
  355.                 } else {
  356.                     // PATH B: Single-valued association
  357.                     $reflFieldValue $reflField->getValue($parentObject);
  358.                     if (! $reflFieldValue || isset($this->_hints[Query::HINT_REFRESH]) || ($reflFieldValue instanceof Proxy && ! $reflFieldValue->__isInitialized())) {
  359.                         // we only need to take action if this value is null,
  360.                         // we refresh the entity or its an uninitialized proxy.
  361.                         if (isset($nonemptyComponents[$dqlAlias])) {
  362.                             $element $this->getEntity($data$dqlAlias);
  363.                             $reflField->setValue($parentObject$element);
  364.                             $this->_uow->setOriginalEntityProperty($oid$relationField$element);
  365.                             $targetClass $this->_metadataCache[$relation['targetEntity']];
  366.                             if ($relation['isOwningSide']) {
  367.                                 // TODO: Just check hints['fetched'] here?
  368.                                 // If there is an inverse mapping on the target class its bidirectional
  369.                                 if ($relation['inversedBy']) {
  370.                                     $inverseAssoc $targetClass->associationMappings[$relation['inversedBy']];
  371.                                     if ($inverseAssoc['type'] & ClassMetadata::TO_ONE) {
  372.                                         $targetClass->reflFields[$inverseAssoc['fieldName']]->setValue($element$parentObject);
  373.                                         $this->_uow->setOriginalEntityProperty(spl_object_hash($element), $inverseAssoc['fieldName'], $parentObject);
  374.                                     }
  375.                                 } elseif ($parentClass === $targetClass && $relation['mappedBy']) {
  376.                                     // Special case: bi-directional self-referencing one-one on the same class
  377.                                     $targetClass->reflFields[$relationField]->setValue($element$parentObject);
  378.                                 }
  379.                             } else {
  380.                                 // For sure bidirectional, as there is no inverse side in unidirectional mappings
  381.                                 $targetClass->reflFields[$relation['mappedBy']]->setValue($element$parentObject);
  382.                                 $this->_uow->setOriginalEntityProperty(spl_object_hash($element), $relation['mappedBy'], $parentObject);
  383.                             }
  384.                             // Update result pointer
  385.                             $this->resultPointers[$dqlAlias] = $element;
  386.                         } else {
  387.                             $this->_uow->setOriginalEntityProperty($oid$relationFieldnull);
  388.                             $reflField->setValue($parentObjectnull);
  389.                         }
  390.                         // else leave $reflFieldValue null for single-valued associations
  391.                     } else {
  392.                         // Update result pointer
  393.                         $this->resultPointers[$dqlAlias] = $reflFieldValue;
  394.                     }
  395.                 }
  396.             } else {
  397.                 // PATH C: Its a root result element
  398.                 $this->rootAliases[$dqlAlias] = true// Mark as root alias
  399.                 $entityKey                    $this->_rsm->entityMappings[$dqlAlias] ?: 0;
  400.                 // if this row has a NULL value for the root result id then make it a null result.
  401.                 if (! isset($nonemptyComponents[$dqlAlias])) {
  402.                     if ($this->_rsm->isMixed) {
  403.                         $result[] = [$entityKey => null];
  404.                     } else {
  405.                         $result[] = null;
  406.                     }
  407.                     $resultKey $this->resultCounter;
  408.                     ++$this->resultCounter;
  409.                     continue;
  410.                 }
  411.                 // check for existing result from the iterations before
  412.                 if (! isset($this->identifierMap[$dqlAlias][$id[$dqlAlias]])) {
  413.                     $element $this->getEntity($data$dqlAlias);
  414.                     if ($this->_rsm->isMixed) {
  415.                         $element = [$entityKey => $element];
  416.                     }
  417.                     if (isset($this->_rsm->indexByMap[$dqlAlias])) {
  418.                         $resultKey $row[$this->_rsm->indexByMap[$dqlAlias]];
  419.                         if (isset($this->_hints['collection'])) {
  420.                             $this->_hints['collection']->hydrateSet($resultKey$element);
  421.                         }
  422.                         $result[$resultKey] = $element;
  423.                     } else {
  424.                         $resultKey $this->resultCounter;
  425.                         ++$this->resultCounter;
  426.                         if (isset($this->_hints['collection'])) {
  427.                             $this->_hints['collection']->hydrateAdd($element);
  428.                         }
  429.                         $result[] = $element;
  430.                     }
  431.                     $this->identifierMap[$dqlAlias][$id[$dqlAlias]] = $resultKey;
  432.                     // Update result pointer
  433.                     $this->resultPointers[$dqlAlias] = $element;
  434.                 } else {
  435.                     // Update result pointer
  436.                     $index                           $this->identifierMap[$dqlAlias][$id[$dqlAlias]];
  437.                     $this->resultPointers[$dqlAlias] = $result[$index];
  438.                     $resultKey                       $index;
  439.                 }
  440.             }
  441.             if (isset($this->_hints[Query::HINT_INTERNAL_ITERATION]) && $this->_hints[Query::HINT_INTERNAL_ITERATION]) {
  442.                 $this->_uow->hydrationComplete();
  443.             }
  444.         }
  445.         if (! isset($resultKey)) {
  446.             $this->resultCounter++;
  447.         }
  448.         // Append scalar values to mixed result sets
  449.         if (isset($rowData['scalars'])) {
  450.             if (! isset($resultKey)) {
  451.                 $resultKey = isset($this->_rsm->indexByMap['scalars'])
  452.                     ? $row[$this->_rsm->indexByMap['scalars']]
  453.                     : $this->resultCounter 1;
  454.             }
  455.             foreach ($rowData['scalars'] as $name => $value) {
  456.                 $result[$resultKey][$name] = $value;
  457.             }
  458.         }
  459.         // Append new object to mixed result sets
  460.         if (isset($rowData['newObjects'])) {
  461.             if (! isset($resultKey)) {
  462.                 $resultKey $this->resultCounter 1;
  463.             }
  464.             $scalarCount = (isset($rowData['scalars']) ? count($rowData['scalars']) : 0);
  465.             foreach ($rowData['newObjects'] as $objIndex => $newObject) {
  466.                 $class $newObject['class'];
  467.                 $args  $newObject['args'];
  468.                 $obj   $class->newInstanceArgs($args);
  469.                 if ($scalarCount === && count($rowData['newObjects']) === 1) {
  470.                     $result[$resultKey] = $obj;
  471.                     continue;
  472.                 }
  473.                 $result[$resultKey][$objIndex] = $obj;
  474.             }
  475.         }
  476.     }
  477.     /**
  478.      * When executed in a hydrate() loop we may have to clear internal state to
  479.      * decrease memory consumption.
  480.      *
  481.      * @param mixed $eventArgs
  482.      *
  483.      * @return void
  484.      */
  485.     public function onClear($eventArgs)
  486.     {
  487.         parent::onClear($eventArgs);
  488.         $aliases array_keys($this->identifierMap);
  489.         $this->identifierMap array_fill_keys($aliases, []);
  490.     }
  491. }