numRows = true; } if ( is_array( $res ) ) { $res = new ArrayIterator( $res ); } $this->res = $res; $this->position = 0; $this->setCurrent( $this->res->current() ); } /** * @see Countable::count * @since 2.5 * * {@inheritDoc} */ public function count() { return $this->numRows ? $this->res->numRows() : $this->res->count(); } /** * @see SeekableIterator::seek * @since 2.5 * * {@inheritDoc} */ public function seek( $position ) { $this->res->seek( $position ); $this->setCurrent( $this->res->current() ); $this->position = $position; } /** * @since 2.5 * * {@inheritDoc} */ public function current() { return $this->current; } /** * @since 2.5 * * {@inheritDoc} */ public function key() { return $this->position; } /** * @since 2.5 * * {@inheritDoc} */ public function next() { $row = $this->res->next(); $this->setCurrent( $row ); $this->position++; } /** * @since 2.5 * * {@inheritDoc} */ public function rewind() { $this->res->rewind(); $this->position = 0; $this->setCurrent( $this->res->current() ); } /** * @since 2.5 * * {@inheritDoc} */ public function valid() { return $this->current !== false; } protected function setCurrent( $row ) { if ( $row === false || $row === null ) { $this->current = false; } else { $this->current = $row; } } }