/** * {@inheritdoc} */ public function translate(string $variable, EntityInterface $meta, ResultInterface $result) : CollectionInterface { if (!$meta instanceof Aggregate) { throw new InvalidArgumentException(); } $rows = $result->rows()->filter(function (RowInterface $row) use($variable) { return $row->column() === $variable; }); $data = new Collection([]); foreach ($rows as $row) { $data = $data->push($this->translateNode($row->value()[$meta->identity()->property()], $meta, $result)); } return $data; }
/** * Translate a raw dbal result into formated data usable for entity factories * * @param ResultInterface $result * @param MapInterface<string, EntityInterface> $variables Association between query variables and entity definitions * * @return MapInterface<string, CollectionInterface> */ public function translate(ResultInterface $result, MapInterface $variables) : MapInterface { $mapped = new Map('string', CollectionInterface::class); $variables->foreach(function (string $variable, EntityInterface $meta) use(&$mapped, $result) { $forVariable = $result->rows()->filter(function (RowInterface $row) use($variable) { return $row->column() === $variable; }); if ($forVariable->count() === 0) { return; } $translator = $this->translators->get(get_class($meta)); $mapped = $mapped->put($variable, $translator->translate($variable, $meta, $result)); }); return $mapped; }