X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2Fresultwrapper%2FFakeResultWrapper.php;h=2ca3d7d51b524c56cd1849e61388bffc5b0f36ef;hb=8eb23f28b63cd33d7997ce4fab0b5968a11147d1;hp=aeb5d8de601b1049d07b34fe7cab0c305ecba6df;hpb=765370a6db20c95907abd9ed1b6d4a285638acb3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php b/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php index aeb5d8de60..2ca3d7d51b 100644 --- a/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php +++ b/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php @@ -9,10 +9,10 @@ use stdClass; * doesn't go anywhere near an actual database. */ class FakeResultWrapper extends ResultWrapper { - /** @var stdClass[] $result */ + /** @var stdClass[]|array[] $result */ /** - * @param stdClass[] $rows + * @param stdClass[]|array[] $rows */ function __construct( array $rows ) { parent::__construct( null, $rows ); @@ -22,43 +22,52 @@ class FakeResultWrapper extends ResultWrapper { return count( $this->result ); } - function fetchRow() { - if ( $this->pos < count( $this->result ) ) { - $this->currentRow = $this->result[$this->pos]; - } else { - $this->currentRow = false; - } - $this->pos++; - if ( is_object( $this->currentRow ) ) { - return get_object_vars( $this->currentRow ); - } else { - return $this->currentRow; - } + function fetchObject() { + $current = $this->current(); + + $this->next(); + + return $current; } - function seek( $row ) { - $this->pos = $row; + function fetchRow() { + $row = $this->valid() ? $this->result[$this->pos] : false; + + $this->next(); + + return is_object( $row ) ? get_object_vars( $row ) : $row; } - function free() { + function seek( $pos ) { + $this->pos = $pos; } - function fetchObject() { - $this->fetchRow(); - if ( $this->currentRow ) { - return (object)$this->currentRow; - } else { - return false; - } + function free() { + $this->result = null; } function rewind() { $this->pos = 0; - $this->currentRow = null; + } + + function current() { + $row = $this->valid() ? $this->result[$this->pos] : false; + + return is_array( $row ) ? (object)$row : $row; + } + + function key() { + return $this->pos; } function next() { - return $this->fetchObject(); + $this->pos++; + + return $this->current(); + } + + function valid() { + return array_key_exists( $this->pos, $this->result ); } }