MediaWiki  master
FakeResultWrapper.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Rdbms;
4 
5 use RuntimeException;
6 use stdClass;
7 
14  protected $result;
15 
19  public function __construct( $result ) {
20  if ( $result instanceof self ) {
21  $this->result = $result->result;
22  } else {
23  $this->result = $result;
24  }
25  }
26 
27  protected function doNumRows() {
28  return count( $this->result );
29  }
30 
31  protected function doFetchObject() {
32  $value = $this->result[$this->currentPos] ?? false;
33  return is_array( $value ) ? (object)$value : $value;
34  }
35 
36  protected function doFetchRow() {
37  $row = $this->doFetchObject();
38  return is_object( $row ) ? get_object_vars( $row ) : $row;
39  }
40 
41  protected function doSeek( $pos ) {
42  }
43 
44  protected function doFree() {
45  $this->result = null;
46  }
47 
48  protected function doGetFieldNames() {
49  // @phan-suppress-previous-line PhanPluginNeverReturnMethod
50  throw new RuntimeException( __METHOD__ . ' is unimplemented' );
51  }
52 }
53 
57 class_alias( FakeResultWrapper::class, 'FakeResultWrapper' );
Wikimedia\Rdbms\FakeResultWrapper\__construct
__construct( $result)
Definition: FakeResultWrapper.php:19
Wikimedia\Rdbms\FakeResultWrapper\doSeek
doSeek( $pos)
Modify the current cursor position to the row with the specified offset.
Definition: FakeResultWrapper.php:41
Wikimedia\Rdbms\FakeResultWrapper\doFree
doFree()
Free underlying data.
Definition: FakeResultWrapper.php:44
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\ResultWrapper\$currentPos
int $currentPos
The offset of the current row that would be returned by current() and may have been previously return...
Definition: ResultWrapper.php:34
Wikimedia\Rdbms\ResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: ResultWrapper.php:23
Wikimedia\Rdbms\FakeResultWrapper
Overloads the relevant methods of the real ResultWrapper so it doesn't go anywhere near an actual dat...
Definition: FakeResultWrapper.php:12
Wikimedia\Rdbms\FakeResultWrapper\doFetchObject
doFetchObject()
Get the next row as a stdClass object, or false if iteration has proceeded past the end.
Definition: FakeResultWrapper.php:31
Wikimedia\Rdbms\FakeResultWrapper\$result
stdClass[] array[] $result
Definition: FakeResultWrapper.php:14
Wikimedia\Rdbms\FakeResultWrapper\doGetFieldNames
doGetFieldNames()
Get the field names in the result set.
Definition: FakeResultWrapper.php:48
Wikimedia\Rdbms\FakeResultWrapper\doFetchRow
doFetchRow()
Get the next row as an array containing the data duplicated, once with string keys and once with nume...
Definition: FakeResultWrapper.php:36
Wikimedia\Rdbms\ResultWrapper\count
count()
Get the number of rows in a result object.
Definition: ResultWrapper.php:125
Wikimedia\Rdbms\FakeResultWrapper\doNumRows
doNumRows()
Get the number of rows in the result set.
Definition: FakeResultWrapper.php:27