1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 07:14:55 +00:00
Arsse/lib/Db/AbstractResult.php
J. King 6da86428c4 Added per-file legal boilerplate
Includes PHPDoc license tag in the file-level block with accompanying copyright notice.

Also added an AUTHORS file on the off chance of outside contributions
2017-11-16 20:51:03 -05:00

61 lines
1.2 KiB
PHP

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\Db;
abstract class AbstractResult implements Result {
protected $pos = 0;
protected $cur = null;
// actual public methods
public function getValue() {
if ($this->valid()) {
$out = array_shift($this->cur);
$this->next();
return $out;
}
$this->next();
return null;
}
public function getRow() {
$out = ($this->valid() ? $this->cur : null);
$this->next();
return $out;
}
public function getAll(): array {
return iterator_to_array($this, false);
}
abstract public function changes();
abstract public function lastId();
// PHP iterator methods
abstract public function valid();
public function next() {
$this->cur = null;
$this->pos += 1;
}
public function current() {
return $this->cur;
}
public function key() {
return $this->pos;
}
public function rewind() {
if ($this->pos) {
throw new Exception("resultReused");
}
}
}