Merge "Linker: Deprecate formatSize()"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / resultwrapper / FakeResultWrapper.php
1 <?php
2 /**
3 * Overloads the relevant methods of the real ResultsWrapper so it
4 * doesn't go anywhere near an actual database.
5 */
6 class FakeResultWrapper extends ResultWrapper {
7 /** @var array */
8 public $result = [];
9
10 /** @var null And it's going to stay that way :D */
11 protected $db = null;
12
13 /** @var int */
14 protected $pos = 0;
15
16 /** @var array|stdClass|bool */
17 protected $currentRow = null;
18
19 /**
20 * @param array $array
21 */
22 function __construct( $array ) {
23 $this->result = $array;
24 }
25
26 /**
27 * @return int
28 */
29 function numRows() {
30 return count( $this->result );
31 }
32
33 /**
34 * @return array|bool
35 */
36 function fetchRow() {
37 if ( $this->pos < count( $this->result ) ) {
38 $this->currentRow = $this->result[$this->pos];
39 } else {
40 $this->currentRow = false;
41 }
42 $this->pos++;
43 if ( is_object( $this->currentRow ) ) {
44 return get_object_vars( $this->currentRow );
45 } else {
46 return $this->currentRow;
47 }
48 }
49
50 function seek( $row ) {
51 $this->pos = $row;
52 }
53
54 function free() {
55 }
56
57 /**
58 * Callers want to be able to access fields with $this->fieldName
59 * @return bool|stdClass
60 */
61 function fetchObject() {
62 $this->fetchRow();
63 if ( $this->currentRow ) {
64 return (object)$this->currentRow;
65 } else {
66 return false;
67 }
68 }
69
70 function rewind() {
71 $this->pos = 0;
72 $this->currentRow = null;
73 }
74
75 /**
76 * @return bool|stdClass
77 */
78 function next() {
79 return $this->fetchObject();
80 }
81 }