Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / db / ORMResult.php
1 <?php
2 /**
3 * Result of a ORMTable::select, which returns IORMRow objects.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @since 1.20
21 *
22 * @file ORMResult.php
23 * @ingroup ORM
24 *
25 * @licence GNU GPL v2 or later
26 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
27 */
28
29 class ORMResult implements Iterator {
30
31 /**
32 * @var ResultWrapper
33 */
34 protected $res;
35
36 /**
37 * @var integer
38 */
39 protected $key;
40
41 /**
42 * @var IORMRow
43 */
44 protected $current;
45
46 /**
47 * @var IORMTable
48 */
49 protected $table;
50
51 /**
52 * @param IORMTable $table
53 * @param ResultWrapper $res
54 */
55 public function __construct( IORMTable $table, ResultWrapper $res ) {
56 $this->table = $table;
57 $this->res = $res;
58 $this->key = 0;
59 $this->setCurrent( $this->res->current() );
60 }
61
62 /**
63 * @param $row
64 */
65 protected function setCurrent( $row ) {
66 if ( $row === false ) {
67 $this->current = false;
68 } else {
69 $this->current = $this->table->newFromDBResult( $row );
70 }
71 }
72
73 /**
74 * @return integer
75 */
76 public function count() {
77 return $this->res->numRows();
78 }
79
80 /**
81 * @return boolean
82 */
83 public function isEmpty() {
84 return $this->res->numRows() === 0;
85 }
86
87 /**
88 * @return IORMRow
89 */
90 public function current() {
91 return $this->current;
92 }
93
94 /**
95 * @return integer
96 */
97 public function key() {
98 return $this->key;
99 }
100
101 public function next() {
102 $row = $this->res->next();
103 $this->setCurrent( $row );
104 $this->key++;
105 }
106
107 public function rewind() {
108 $this->res->rewind();
109 $this->key = 0;
110 $this->setCurrent( $this->res->current() );
111 }
112
113 /**
114 * @return boolean
115 */
116 public function valid() {
117 return $this->current !== false;
118 }
119
120 }