[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/db/ -> ORMResult.php (source)

   1  <?php
   2  /**
   3   * ORMIterator that takes a ResultWrapper object returned from
   4   * a select operation returning IORMRow objects (ie IORMTable::select).
   5   *
   6   * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
   7   *
   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.
  12   *
  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.
  17   *
  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
  22   *
  23   * @since 1.20
  24   *
  25   * @file ORMResult.php
  26   * @ingroup ORM
  27   *
  28   * @license GNU GPL v2 or later
  29   * @author Jeroen De Dauw < [email protected] >
  30   */
  31  
  32  class ORMResult implements ORMIterator {
  33      /**
  34       * @var ResultWrapper
  35       */
  36      protected $res;
  37  
  38      /**
  39       * @var int
  40       */
  41      protected $key;
  42  
  43      /**
  44       * @var IORMRow
  45       */
  46      protected $current;
  47  
  48      /**
  49       * @var IORMTable
  50       */
  51      protected $table;
  52  
  53      /**
  54       * @param IORMTable $table
  55       * @param ResultWrapper $res
  56       */
  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() );
  62      }
  63  
  64      /**
  65       * @param bool|object $row
  66       */
  67  	protected function setCurrent( $row ) {
  68          if ( $row === false ) {
  69              $this->current = false;
  70          } else {
  71              $this->current = $this->table->newRowFromDBResult( $row );
  72          }
  73      }
  74  
  75      /**
  76       * @return int
  77       */
  78  	public function count() {
  79          return $this->res->numRows();
  80      }
  81  
  82      /**
  83       * @return bool
  84       */
  85  	public function isEmpty() {
  86          return $this->res->numRows() === 0;
  87      }
  88  
  89      /**
  90       * @return IORMRow
  91       */
  92  	public function current() {
  93          return $this->current;
  94      }
  95  
  96      /**
  97       * @return int
  98       */
  99  	public function key() {
 100          return $this->key;
 101      }
 102  
 103  	public function next() {
 104          $row = $this->res->next();
 105          $this->setCurrent( $row );
 106          $this->key++;
 107      }
 108  
 109  	public function rewind() {
 110          $this->res->rewind();
 111          $this->key = 0;
 112          $this->setCurrent( $this->res->current() );
 113      }
 114  
 115      /**
 116       * @return bool
 117       */
 118  	public function valid() {
 119          return $this->current !== false;
 120      }
 121  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1