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
23 namespace MediaWiki\User
;
27 use Wikimedia\Rdbms\IResultWrapper
;
29 class UserArrayFromResult
extends UserArray
implements Countable
{
30 /** @var IResultWrapper */
36 /** @var User|false */
40 * @param IResultWrapper $res
42 public function __construct( $res ) {
45 $this->setCurrent( $this->res
->current() );
49 * @param stdClass|false $row
52 protected function setCurrent( $row ) {
53 if ( $row === false ) {
54 $this->current
= false;
56 $this->current
= User
::newFromRow( $row );
63 public function count(): int {
64 return $this->res
->numRows();
67 public function current(): User
{
68 return $this->current
;
71 public function key(): int {
75 public function next(): void
{
76 $row = $this->res
->fetchObject();
77 $this->setCurrent( $row );
81 public function rewind(): void
{
84 $this->setCurrent( $this->res
->current() );
90 public function valid(): bool {
91 return $this->current
!== false;
95 /** @deprecated class alias since 1.41 */
96 class_alias( UserArrayFromResult
::class, 'UserArrayFromResult' );