You are here

class ParserCSVIterator in Feeds 8.2

Text lines from file iterator.

Hierarchy

Expanded class hierarchy of ParserCSVIterator

3 files declare their use of ParserCSVIterator
FeedsCSVParser.php in lib/Drupal/feeds/Plugin/feeds/parser/FeedsCSVParser.php
Contains the FeedsCSVParser class.
FeedsSimplePieParser.php in lib/Drupal/feeds/Plugin/feeds/parser/FeedsSimplePieParser.php
Contains FeedsSimplePieParser and related classes.
ParserCSVTest.php in lib/Drupal/feeds/Tests/ParserCSVTest.php
Tests for ParserCSV library.

File

lib/Drupal/feeds/ParserCSVIterator.php, line 10

Namespace

Drupal\feeds
View source
class ParserCSVIterator implements Iterator {
  private $handle;
  private $currentLine;
  private $currentPos;
  public function __construct($filepath) {
    $this->handle = fopen($filepath, 'r');
    $this->currentLine = NULL;
    $this->currentPos = NULL;
  }
  function __destruct() {
    if ($this->handle) {
      fclose($this->handle);
    }
  }
  public function rewind($pos = 0) {
    if ($this->handle) {
      fseek($this->handle, $pos);
      $this
        ->next();
    }
  }
  public function next() {
    if ($this->handle) {
      $this->currentLine = feof($this->handle) ? NULL : fgets($this->handle);
      $this->currentPos = ftell($this->handle);
      return $this->currentLine;
    }
  }
  public function valid() {
    return isset($this->currentLine);
  }
  public function current() {
    return $this->currentLine;
  }
  public function currentPos() {
    return $this->currentPos;
  }
  public function key() {
    return 'line';
  }

}

Members