/** * Map targets to entities * * @param array $entities * @param array $targets */ protected function map($entities, $targets) { $identifier = $this->targetMetadata->getIdentifier(); foreach ($targets as $target) { $id = $this->targetMetadata->getValue($target, $this->keyTo, true); foreach ($entities as $entity) { if ($id == $this->metadata->getValue($entity, $this->keyFrom, true)) { $value = $this->metadata->getValue($entity, $this->name); if (is_array($value)) { $value[$this->targetMetadata->getValue($target, $identifier)] = $target; } else { $value = $target; } $this->metadata->setValue($entity, $this->name, $value); } } } }
/** * Hydrates all rows returned by the passed statement instance at once. * * @param object $statement * @param Metadata $metadata * @return mixed */ public function hydrateAll($statement, Metadata $metadata) { $result = []; $identifier = $metadata->getIdentifier(); while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { $entity = $this->load($metadata, $row, true, true); $result[$metadata->getValue($entity, $identifier)] = $entity; } return $result; }