_colNames = $colNames; $this->_colQty = count($colNames); } /** * Column names getter. * * @return array */ public function getColNames() { return $this->_colNames; } /** * Return the current element * * Returns the row in associative array format: array( => , ...) * * @return array */ public function current() { $row = $this->_row; if (count($row) != $this->_colQty) { if ($this->_foundWrongQuoteFlag) { throw new \InvalidArgumentException(AbstractEntity::ERROR_CODE_WRONG_QUOTES); } else { throw new \InvalidArgumentException(AbstractEntity::ERROR_CODE_COLUMNS_NUMBER); } } return array_combine($this->_colNames, $row); } /** * Move forward to next element (\Iterator interface) * * @return void */ public function next() { $this->_key++; $row = $this->_getNextRow(); if (false === $row || [] === $row) { $this->_row = []; $this->_key = -1; } else { $this->_row = $row; } } /** * Render next row * * Return array or false on error * * @return array|false */ abstract protected function _getNextRow(); /** * Return the key of the current element (\Iterator interface) * * @return int -1 if out of bounds, 0 or more otherwise */ public function key() { return $this->_key; } /** * Checks if current position is valid (\Iterator interface) * * @return bool */ public function valid() { return -1 !== $this->_key; } /** * Rewind the \Iterator to the first element (\Iterator interface) * * @return void */ public function rewind() { $this->_key = -1; $this->_row = []; $this->next(); } /** * Seeks to a position (Seekable interface) * * @param int $position The position to seek to 0 or more * @return void * @throws \OutOfBoundsException */ public function seek($position) { if ($position == $this->_key) { return; } if (0 == $position || $position < $this->_key) { $this->rewind(); } if ($position > 0) { do { $this->next(); if ($this->_key == $position) { return; } } while ($this->_key != -1); } throw new \OutOfBoundsException('Please correct the seek position.'); } }