web-base/Core/Driver/SQL/RowIterator.class.php

40 lines
867 B
PHP
Raw Permalink Normal View History

2022-06-08 18:37:08 +02:00
<?php
2022-11-18 18:06:46 +01:00
namespace Core\Driver\SQL;
2022-06-08 18:37:08 +02:00
abstract class RowIterator implements \Iterator {
protected $resultSet;
protected int $rowIndex;
protected array $fetchedRows;
protected int $numRows;
protected bool $useCache;
public function __construct($resultSet, bool $useCache = false) {
$this->resultSet = $resultSet;
$this->fetchedRows = [];
$this->rowIndex = 0;
$this->numRows = $this->getNumRows();
$this->useCache = $useCache;
}
protected abstract function getNumRows(): int;
protected abstract function fetchRow(int $index): array;
2024-04-04 12:46:58 +02:00
public function current(): array {
2022-06-08 18:37:08 +02:00
return $this->fetchRow($this->rowIndex);
}
2024-04-04 12:46:58 +02:00
public function next(): void {
2022-06-08 18:37:08 +02:00
$this->rowIndex++;
}
2024-04-04 12:46:58 +02:00
public function key(): int {
2022-06-08 18:37:08 +02:00
return $this->rowIndex;
}
public function valid(): bool {
return $this->rowIndex < $this->numRows;
}
}