MediaWiki  master
FakeResultWrapper.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Rdbms;
4 
5 use 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  // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
63  $row = $this->valid() ? $this->result[$this->pos] : false;
64 
65  return is_array( $row ) ? (object)$row : $row;
66  }
67 
68  public function key() {
69  return $this->pos;
70  }
71 
72  public function next() {
73  $this->pos++;
74 
75  return $this->current();
76  }
77 
78  public function valid() {
79  return array_key_exists( $this->pos, $this->result );
80  }
81 }
82 
86 class_alias( FakeResultWrapper::class, 'FakeResultWrapper' );
Wikimedia\Rdbms\FakeResultWrapper\__construct
__construct( $result)
Definition: FakeResultWrapper.php:21
Wikimedia\Rdbms\FakeResultWrapper\current
current()
Definition: FakeResultWrapper.php:61
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\FakeResultWrapper\rewind
rewind()
Definition: FakeResultWrapper.php:57
Wikimedia\Rdbms\FakeResultWrapper
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Definition: FakeResultWrapper.php:11
Wikimedia\Rdbms\FakeResultWrapper\$result
stdClass[] array[] $result
Definition: FakeResultWrapper.php:13
Wikimedia\Rdbms\FakeResultWrapper\free
free()
Free a result object.
Definition: FakeResultWrapper.php:53
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
Wikimedia\Rdbms\FakeResultWrapper\seek
seek( $pos)
Change the position of the cursor in a result object.
Definition: FakeResultWrapper.php:49
Wikimedia\Rdbms\FakeResultWrapper\$pos
int $pos
Definition: FakeResultWrapper.php:16
Wikimedia\Rdbms\FakeResultWrapper\fetchRow
fetchRow()
Fetch the next row from the given result object, in associative array form.
Definition: FakeResultWrapper.php:41
Wikimedia\Rdbms\FakeResultWrapper\numRows
numRows()
Get the number of rows in a result object.
Definition: FakeResultWrapper.php:29
Wikimedia\Rdbms\FakeResultWrapper\key
key()
Definition: FakeResultWrapper.php:68
Wikimedia\Rdbms\FakeResultWrapper\valid
valid()
Definition: FakeResultWrapper.php:78
Wikimedia\Rdbms\FakeResultWrapper\fetchObject
fetchObject()
Fetch the next row from the given result object, in object form.
Definition: FakeResultWrapper.php:33
Wikimedia\Rdbms\FakeResultWrapper\next
next()
Definition: FakeResultWrapper.php:72