Merge "Handle missing namespace prefix in XML dumps more gracefully"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / resultwrapper / FakeResultWrapper.php
1 <?php
2
3 namespace Wikimedia\Rdbms;
4
5 use stdClass;
6
7 /**
8 * Overloads the relevant methods of the real ResultsWrapper so it
9 * doesn't go anywhere near an actual database.
10 */
11 class FakeResultWrapper extends ResultWrapper {
12 /** @var $result stdClass[] */
13
14 /**
15 * @param stdClass[] $rows
16 */
17 function __construct( array $rows ) {
18 parent::__construct( null, $rows );
19 }
20
21 function numRows() {
22 return count( $this->result );
23 }
24
25 function fetchRow() {
26 if ( $this->pos < count( $this->result ) ) {
27 $this->currentRow = $this->result[$this->pos];
28 } else {
29 $this->currentRow = false;
30 }
31 $this->pos++;
32 if ( is_object( $this->currentRow ) ) {
33 return get_object_vars( $this->currentRow );
34 } else {
35 return $this->currentRow;
36 }
37 }
38
39 function seek( $row ) {
40 $this->pos = $row;
41 }
42
43 function free() {
44 }
45
46 function fetchObject() {
47 $this->fetchRow();
48 if ( $this->currentRow ) {
49 return (object)$this->currentRow;
50 } else {
51 return false;
52 }
53 }
54
55 function rewind() {
56 $this->pos = 0;
57 $this->currentRow = null;
58 }
59
60 function next() {
61 return $this->fetchObject();
62 }
63 }
64
65 class_alias( FakeResultWrapper::class, 'FakeResultWrapper' );
66