Merge "rdbms: combine trxLevel and trxShortId fields in Database"
[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 stdClass[]|array[] $result */
13
14 /**
15 * @param stdClass[]|array[] $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 fetchObject() {
26 $current = $this->current();
27
28 $this->next();
29
30 return $current;
31 }
32
33 function fetchRow() {
34 $row = $this->valid() ? $this->result[$this->pos] : false;
35
36 $this->next();
37
38 return is_object( $row ) ? get_object_vars( $row ) : $row;
39 }
40
41 function seek( $pos ) {
42 $this->pos = $pos;
43 }
44
45 function free() {
46 $this->result = null;
47 }
48
49 function rewind() {
50 $this->pos = 0;
51 }
52
53 function current() {
54 $row = $this->valid() ? $this->result[$this->pos] : false;
55
56 return is_array( $row ) ? (object)$row : $row;
57 }
58
59 function key() {
60 return $this->pos;
61 }
62
63 function next() {
64 $this->pos++;
65
66 return $this->current();
67 }
68
69 function valid() {
70 return array_key_exists( $this->pos, $this->result );
71 }
72 }
73
74 /**
75 * @deprecated since 1.29
76 */
77 class_alias( FakeResultWrapper::class, 'FakeResultWrapper' );