2017-11-06 03:28:19 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-11-06 03:28:19 +00:00
|
|
|
declare(strict_types=1);
|
2021-04-14 15:17:01 +00:00
|
|
|
|
2017-11-06 03:28:19 +00:00
|
|
|
namespace JKingWeb\Arsse\Db;
|
|
|
|
|
|
|
|
abstract class AbstractResult implements Result {
|
|
|
|
protected $pos = 0;
|
|
|
|
protected $cur = null;
|
|
|
|
|
|
|
|
// actual public methods
|
|
|
|
|
|
|
|
public function getValue() {
|
|
|
|
if ($this->valid()) {
|
2017-11-07 04:32:29 +00:00
|
|
|
$out = array_shift($this->cur);
|
|
|
|
$this->next();
|
|
|
|
return $out;
|
2017-11-19 20:49:41 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
2017-11-06 03:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:34:03 +00:00
|
|
|
public function getRow(): ?array {
|
2017-11-19 20:49:41 +00:00
|
|
|
if ($this->valid()) {
|
|
|
|
$out = $this->cur;
|
|
|
|
$this->next();
|
|
|
|
return $out;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-11-06 03:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAll(): array {
|
|
|
|
return iterator_to_array($this, false);
|
|
|
|
}
|
|
|
|
|
2018-11-02 16:01:03 +00:00
|
|
|
abstract public function changes(): int;
|
2017-11-06 03:28:19 +00:00
|
|
|
|
2018-11-02 16:01:03 +00:00
|
|
|
abstract public function lastId(): int;
|
2017-11-06 03:28:19 +00:00
|
|
|
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|