You are here

class LineIterator in Feeds extensible parsers 8

Text lines from file iterator.

Hierarchy

  • class \Drupal\feeds_ex\File\LineIterator extends \SplFileObject

Expanded class hierarchy of LineIterator

3 files declare their use of LineIterator
JmesPathLinesParser.php in src/Feeds/Parser/JmesPathLinesParser.php
JsonPathLinesParser.php in src/Feeds/Parser/JsonPathLinesParser.php
LineIteratorTest.php in tests/src/Unit/File/LineIteratorTest.php

File

src/File/LineIterator.php, line 10

Namespace

Drupal\feeds_ex\File
View source
class LineIterator 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;
  }

  /**
   * 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
LineIterator::$lineLimit protected property The number of lines to read.
LineIterator::$linesRead protected property The number of lines that have been read.
LineIterator::$startPosition protected property The position to start in the file.
LineIterator::next public function Implements Iterator::next().
LineIterator::rewind public function Implements Iterator::rewind().
LineIterator::setLineLimit public function Sets the number of lines to read.
LineIterator::setStartPosition public function Sets the starting position.
LineIterator::valid public function Implements Iterator::valid().