mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 08:34:56 +00:00
42a5ccb96c
Queries for multiple specific articles are limited in size because of limits on the number of bound query parameters. Currently this limit is somewhat arbitrarily set at 50, but it may increase. Historically controllers would be responsible for chunking input, but this will present problems when the expected output is a result set, and of course the maintenance burden increases as the number of controllers increases. This commit transfers the burden to the data model, and consequently introduces a ResultAggregate class which collects chunked result sets (currently only for articleList). In the course of making these changes the mock Result class was also largely rewritten, fixing many bugs with it. This commit does not modify the controllers nor their tests; this will be done in a subsequent commit.
76 lines
1.6 KiB
PHP
76 lines
1.6 KiB
PHP
<?php
|
|
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() {
|
|
if ($this->valid()) {
|
|
$keys = array_keys($this->current());
|
|
$out = $this->current()[array_shift($keys)];
|
|
$this->next();
|
|
return $out;
|
|
}
|
|
$this->next();
|
|
return null;
|
|
}
|
|
|
|
public function getRow() {
|
|
$out = ($this->valid() ? $this->current() : null);
|
|
$this->next();
|
|
return $out;
|
|
}
|
|
|
|
public function getAll(): array {
|
|
return iterator_to_array($this, false);
|
|
}
|
|
|
|
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() {
|
|
return $this->pos < sizeof($this->set);
|
|
}
|
|
|
|
public function next() {
|
|
$this->pos++;
|
|
}
|
|
|
|
public function current() {
|
|
return $this->set[$this->key()];
|
|
}
|
|
|
|
public function key() {
|
|
return array_keys($this->set)[$this->pos];
|
|
}
|
|
|
|
public function rewind() {
|
|
$this->pos = 0;
|
|
}
|
|
}
|