Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / includes / db / ORMResult.php
blob327d20d9e43c60541928b9669f5f06f563137adc
1 <?php
2 /**
3 * ORMIterator that takes a ResultWrapper object returned from
4 * a select operation returning IORMRow objects (ie IORMTable::select).
6 * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @since 1.20
25 * @file ORMResult.php
26 * @ingroup ORM
28 * @license GNU GPL v2 or later
29 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
32 class ORMResult implements ORMIterator {
33 /**
34 * @var ResultWrapper
36 protected $res;
38 /**
39 * @var int
41 protected $key;
43 /**
44 * @var IORMRow
46 protected $current;
48 /**
49 * @var IORMTable
51 protected $table;
53 /**
54 * @param IORMTable $table
55 * @param ResultWrapper $res
57 public function __construct( IORMTable $table, ResultWrapper $res ) {
58 $this->table = $table;
59 $this->res = $res;
60 $this->key = 0;
61 $this->setCurrent( $this->res->current() );
64 /**
65 * @param bool|object $row
67 protected function setCurrent( $row ) {
68 if ( $row === false ) {
69 $this->current = false;
70 } else {
71 $this->current = $this->table->newRowFromDBResult( $row );
75 /**
76 * @return int
78 public function count() {
79 return $this->res->numRows();
82 /**
83 * @return bool
85 public function isEmpty() {
86 return $this->res->numRows() === 0;
89 /**
90 * @return IORMRow
92 public function current() {
93 return $this->current;
96 /**
97 * @return int
99 public function key() {
100 return $this->key;
103 public function next() {
104 $row = $this->res->next();
105 $this->setCurrent( $row );
106 $this->key++;
109 public function rewind() {
110 $this->res->rewind();
111 $this->key = 0;
112 $this->setCurrent( $this->res->current() );
116 * @return bool
118 public function valid() {
119 return $this->current !== false;