Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / db / ORMResult.php
blob160033c4cf23ae3d3b08625969466e1aeb40a75c
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 {
34 /**
35 * @var ResultWrapper
37 protected $res;
39 /**
40 * @var integer
42 protected $key;
44 /**
45 * @var IORMRow
47 protected $current;
49 /**
50 * @var IORMTable
52 protected $table;
54 /**
55 * @param IORMTable $table
56 * @param ResultWrapper $res
58 public function __construct( IORMTable $table, ResultWrapper $res ) {
59 $this->table = $table;
60 $this->res = $res;
61 $this->key = 0;
62 $this->setCurrent( $this->res->current() );
65 /**
66 * @param $row
68 protected function setCurrent( $row ) {
69 if ( $row === false ) {
70 $this->current = false;
71 } else {
72 $this->current = $this->table->newRowFromDBResult( $row );
76 /**
77 * @return integer
79 public function count() {
80 return $this->res->numRows();
83 /**
84 * @return boolean
86 public function isEmpty() {
87 return $this->res->numRows() === 0;
90 /**
91 * @return IORMRow
93 public function current() {
94 return $this->current;
97 /**
98 * @return integer
100 public function key() {
101 return $this->key;
104 public function next() {
105 $row = $this->res->next();
106 $this->setCurrent( $row );
107 $this->key++;
110 public function rewind() {
111 $this->res->rewind();
112 $this->key = 0;
113 $this->setCurrent( $this->res->current() );
117 * @return boolean
119 public function valid() {
120 return $this->current !== false;