protected function createEntities(array $rows, $entityClass = null, $table = null)
{
if ($table === null) {
$table = $this->getTable();
}
$entities = [];
$collection = Result::createInstance($rows, $table, $this->connection, $this->mapper);
$primaryKey = $this->mapper->getPrimaryKey($this->getTable());
if ($entityClass !== null) {
foreach ($rows as $dibiRow) {
$entity = $this->entityFactory->createEntity($entityClass, $collection->getRow($dibiRow->{$primaryKey}));
$entity->makeAlive($this->entityFactory);
$entities[$dibiRow->{$primaryKey}] = $entity;
}
} else {
foreach ($rows as $dibiRow) {
$row = $collection->getRow($dibiRow->{$primaryKey});
$entityClass = $this->mapper->getEntityClass($this->getTable(), $row);
$entity = $this->entityFactory->createEntity($entityClass, $row);
$entity->makeAlive($this->entityFactory);
$entities[$dibiRow->{$primaryKey}] = $entity;
}
}
return $this->entityFactory->createCollection($entities);
}