diff options
Diffstat (limited to 'www/wiki/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php')
-rw-r--r-- | www/wiki/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/www/wiki/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php b/www/wiki/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php new file mode 100644 index 00000000..12e59b59 --- /dev/null +++ b/www/wiki/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php @@ -0,0 +1,65 @@ +<?php + +namespace Wikimedia\Rdbms; + +use stdClass; + +/** + * Overloads the relevant methods of the real ResultsWrapper so it + * doesn't go anywhere near an actual database. + */ +class FakeResultWrapper extends ResultWrapper { + /** @var stdClass[] $result */ + + /** + * @param stdClass[] $rows + */ + function __construct( array $rows ) { + parent::__construct( null, $rows ); + } + + function numRows() { + 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 seek( $row ) { + $this->pos = $row; + } + + function free() { + } + + function fetchObject() { + $this->fetchRow(); + if ( $this->currentRow ) { + return (object)$this->currentRow; + } else { + return false; + } + } + + function rewind() { + $this->pos = 0; + $this->currentRow = null; + } + + function next() { + return $this->fetchObject(); + } +} + +class_alias( FakeResultWrapper::class, 'FakeResultWrapper' ); |