MediaWiki REL1_34
FakeResultWrapper.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use stdClass;
6
13 protected $result;
14
16 protected $pos = 0;
17
21 public function __construct( $result ) {
22 if ( $result instanceof self ) {
23 $this->result = $result->result;
24 } else {
25 $this->result = $result;
26 }
27 }
28
29 public function numRows() {
30 return count( $this->result );
31 }
32
33 public function fetchObject() {
34 $current = $this->current();
35
36 $this->next();
37
38 return $current;
39 }
40
41 public function fetchRow() {
42 $row = $this->valid() ? $this->result[$this->pos] : false;
43
44 $this->next();
45
46 return is_object( $row ) ? get_object_vars( $row ) : $row;
47 }
48
49 public function seek( $pos ) {
50 $this->pos = $pos;
51 }
52
53 public function free() {
54 $this->result = null;
55 }
56
57 public function rewind() {
58 $this->pos = 0;
59 }
60
61 public function current() {
62 $row = $this->valid() ? $this->result[$this->pos] : false;
63
64 return is_array( $row ) ? (object)$row : $row;
65 }
66
67 public function key() {
68 return $this->pos;
69 }
70
71 public function next() {
72 $this->pos++;
73
74 return $this->current();
75 }
76
77 public function valid() {
78 return array_key_exists( $this->pos, $this->result );
79 }
80}
81
85class_alias( FakeResultWrapper::class, 'FakeResultWrapper' );
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
fetchObject()
Fetch the next row from the given result object, in object form.
seek( $pos)
Change the position of the cursor in a result object.
numRows()
Get the number of rows in a result object.
fetchRow()
Fetch the next row from the given result object, in associative array form.
Result wrapper for grabbing data queried from an IDatabase object.