2017-04-02 03:06:52 +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-04-02 03:06:52 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Test;
|
|
|
|
|
|
|
|
class Result implements \JKingWeb\Arsse\Db\Result {
|
|
|
|
protected $st;
|
|
|
|
protected $set;
|
|
|
|
protected $pos = 0;
|
|
|
|
protected $cur = null;
|
|
|
|
protected $rows = 0;
|
|
|
|
protected $id = 0;
|
|
|
|
|
|
|
|
// actual public methods
|
|
|
|
|
|
|
|
public function getValue() {
|
2017-08-29 14:50:31 +00:00
|
|
|
if ($this->valid()) {
|
2017-11-07 04:32:29 +00:00
|
|
|
$keys = array_keys($this->current());
|
|
|
|
$out = $this->current()[array_shift($keys)];
|
|
|
|
$this->next();
|
|
|
|
return $out;
|
2017-04-02 03:06:52 +00:00
|
|
|
}
|
2017-11-07 04:32:29 +00:00
|
|
|
$this->next();
|
2017-04-02 03:06:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRow() {
|
2017-11-07 04:32:29 +00:00
|
|
|
$out = ($this->valid() ? $this->current() : null);
|
|
|
|
$this->next();
|
|
|
|
return $out;
|
2017-04-02 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAll(): array {
|
2017-11-07 04:32:29 +00:00
|
|
|
return iterator_to_array($this, false);
|
2017-04-02 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function changes() {
|
|
|
|
return $this->rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function lastId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// constructor/destructor
|
|
|
|
|
|
|
|
public function __construct(array $result, int $changes = 0, int $lastID = 0) {
|
|
|
|
$this->set = $result;
|
|
|
|
$this->rows = $changes;
|
|
|
|
$this->id = $lastID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __destruct() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// PHP iterator methods
|
|
|
|
|
|
|
|
public function valid() {
|
2017-11-07 04:32:29 +00:00
|
|
|
return $this->pos < sizeof($this->set);
|
2017-04-02 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function next() {
|
2017-11-07 04:32:29 +00:00
|
|
|
$this->pos++;
|
2017-04-02 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function current() {
|
2017-11-07 04:32:29 +00:00
|
|
|
return $this->set[$this->key()];
|
2017-04-02 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function key() {
|
2017-11-07 04:32:29 +00:00
|
|
|
return array_keys($this->set)[$this->pos];
|
2017-04-02 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rewind() {
|
2017-11-07 04:32:29 +00:00
|
|
|
$this->pos = 0;
|
2017-04-02 03:06:52 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|