| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\User; |
| 24 |
|
| 25 |
use Countable; |
| 26 |
use stdClass; |
| 27 |
use Wikimedia\Rdbms\IResultWrapper; |
| 28 |
|
| 29 |
class UserArrayFromResult extends UserArray implements Countable { |
| 30 |
|
| 31 |
public $res; |
| 32 |
|
| 33 |
|
| 34 |
public $key; |
| 35 |
|
| 36 |
|
| 37 |
public $current; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function __construct( $res ) { |
| 43 |
$this->res = $res; |
| 44 |
$this->key = 0; |
| 45 |
$this->setCurrent( $this->res->current() ); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
protected function setCurrent( $row ) { |
| 53 |
if ( $row === false ) { |
| 54 |
$this->current = false; |
| 55 |
} else { |
| 56 |
$this->current = User::newFromRow( $row ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public function count(): int { |
| 64 |
return $this->res->numRows(); |
| 65 |
} |
| 66 |
|
| 67 |
public function current(): User { |
| 68 |
return $this->current; |
| 69 |
} |
| 70 |
|
| 71 |
public function key(): int { |
| 72 |
return $this->key; |
| 73 |
} |
| 74 |
|
| 75 |
public function next(): void { |
| 76 |
$row = $this->res->fetchObject(); |
| 77 |
$this->setCurrent( $row ); |
| 78 |
$this->key++; |
| 79 |
} |
| 80 |
|
| 81 |
public function rewind(): void { |
| 82 |
$this->res->rewind(); |
| 83 |
$this->key = 0; |
| 84 |
$this->setCurrent( $this->res->current() ); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public function valid(): bool { |
| 91 |
return $this->current !== false; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
class_alias( UserArrayFromResult::class, 'UserArrayFromResult' ); |