You are here

class FeedsExLineIterator in Feeds extensible parsers 7.2

Same name and namespace in other branches
  1. 7 src/File/FeedsExLineIterator.php \FeedsExLineIterator

Text lines from file iterator.

Hierarchy

Expanded class hierarchy of FeedsExLineIterator

File

src/File/FeedsExLineIterator.php, line 11
Contains FeedsExLineIterator.

View source
class FeedsExLineIterator extends SplFileObject {

  /**
   * The position to start in the file.
   *
   * @var int
   */
  protected $startPosition = 0;

  /**
   * The number of lines to read.
   *
   * @var init
   */
  protected $lineLimit;

  /**
   * The number of lines that have been read.
   *
   * @var init
   */
  protected $linesRead = 0;

  /**
   * Implements Iterator::rewind().
   */
  public function rewind() {
    parent::rewind();
    if ($this->startPosition) {
      $this
        ->fseek($this->startPosition);
    }
    $this->linesRead = 0;
  }

  /**
   * Implements Iterator::next().
   */
  public function next() {
    $this->linesRead++;
    parent::next();
  }

  /**
   * Implements Iterator::valid().
   */
  public function valid() {
    return (!$this->lineLimit || $this->linesRead < $this->lineLimit) && parent::valid() && parent::current();
  }

  /**
   * Sets the number of lines to read.
   *
   * @param int $limit
   *   The number of lines to read.
   */
  public function setLineLimit($limit) {
    $this->lineLimit = (int) $limit;
  }

  /**
   * Returns the number of lines read.
   *
   * @return int
   *   The number of lines read.
   */
  public function getLinesRead() {
    return $this->linesRead;
  }

  /**
   * Sets the starting position.
   *
   * @param int $position
   *   The position to start in the file.
   */
  public function setStartPosition($position) {
    $this->startPosition = (int) $position;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsExLineIterator::$lineLimit protected property The number of lines to read.
FeedsExLineIterator::$linesRead protected property The number of lines that have been read.
FeedsExLineIterator::$startPosition protected property The position to start in the file.
FeedsExLineIterator::getLinesRead public function Returns the number of lines read.
FeedsExLineIterator::next public function Implements Iterator::next().
FeedsExLineIterator::rewind public function Implements Iterator::rewind().
FeedsExLineIterator::setLineLimit public function Sets the number of lines to read.
FeedsExLineIterator::setStartPosition public function Sets the starting position.
FeedsExLineIterator::valid public function Implements Iterator::valid().