LeanMapper\Repository::createEntities PHP Method

createEntities() protected method

Creates new set of Entity's instances from given array of \Dibi\Row instances
protected createEntities ( array $rows, string | null $entityClass = null, string | null $table = null ) : array
$rows array
$entityClass string | null
$table string | null
return array
    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);
    }