3 * Class to walk into a list of Title objects.
5 * Note: this entire file is a byte-for-byte copy of UserArrayFromResult.php
6 * with s/User/Title/. If anyone can figure out how to do this nicely
7 * with inheritance or something, please do so.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
27 namespace MediaWiki\Title
;
31 use Wikimedia\Rdbms\IResultWrapper
;
35 * @note marked as newable in 1.35 for lack of a better alternative,
36 * but should probably become part of the TitleFactory service.
38 class TitleArrayFromResult
implements Countable
, Iterator
{
39 /** @var IResultWrapper */
45 /** @var Title|false */
51 * @param IResultWrapper $res
53 public function __construct( $res ) {
56 $this->setCurrent( $this->res
->current() );
60 * @param \stdClass|false $row
63 protected function setCurrent( $row ) {
64 if ( $row === false ) {
65 $this->current
= false;
67 $this->current
= Title
::newFromRow( $row );
74 public function count(): int {
75 return $this->res
->numRows();
78 public function current(): Title
{
79 return $this->current
;
82 public function key(): int {
86 public function next(): void
{
87 $row = $this->res
->fetchObject();
88 $this->setCurrent( $row );
92 public function rewind(): void
{
95 $this->setCurrent( $this->res
->current() );
101 public function valid(): bool {
102 return $this->current
!== false;
106 /** @deprecated class alias since 1.41 */
107 class_alias( TitleArrayFromResult
::class, 'TitleArrayFromResult' );