Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / user / UserArrayFromResult.php
blobf9d19d1b30786e62ada3e6ecb37c417ef1d6e938
1 <?php
2 /**
3 * Class to walk into a list of User objects.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 namespace MediaWiki\User;
25 use Countable;
26 use stdClass;
27 use Wikimedia\Rdbms\IResultWrapper;
29 class UserArrayFromResult extends UserArray implements Countable {
30 /** @var IResultWrapper */
31 public $res;
33 /** @var int */
34 public $key;
36 /** @var User|false */
37 public $current;
39 /**
40 * @param IResultWrapper $res
42 public function __construct( $res ) {
43 $this->res = $res;
44 $this->key = 0;
45 $this->setCurrent( $this->res->current() );
48 /**
49 * @param stdClass|false $row
50 * @return void
52 protected function setCurrent( $row ) {
53 if ( $row === false ) {
54 $this->current = false;
55 } else {
56 $this->current = User::newFromRow( $row );
60 /**
61 * @return int
63 public function count(): int {
64 return $this->res->numRows();
67 public function current(): User {
68 return $this->current;
71 public function key(): int {
72 return $this->key;
75 public function next(): void {
76 $row = $this->res->fetchObject();
77 $this->setCurrent( $row );
78 $this->key++;
81 public function rewind(): void {
82 $this->res->rewind();
83 $this->key = 0;
84 $this->setCurrent( $this->res->current() );
87 /**
88 * @return bool
90 public function valid(): bool {
91 return $this->current !== false;
95 /** @deprecated class alias since 1.41 */
96 class_alias( UserArrayFromResult::class, 'UserArrayFromResult' );