You are here

public function FeedsCSVParser::parse in Feeds 6

Same name and namespace in other branches
  1. 7.2 plugins/FeedsCSVParser.inc \FeedsCSVParser::parse()
  2. 7 plugins/FeedsCSVParser.inc \FeedsCSVParser::parse()

Implementation of FeedsParser::parse().

Overrides FeedsParser::parse

File

plugins/FeedsCSVParser.inc, line 11

Class

FeedsCSVParser
Parses a given file as a CSV file.

Code

public function parse(FeedsImportBatch $batch, FeedsSource $source) {

  // Load and configure parser.
  feeds_include_library('ParserCSV.inc', 'ParserCSV');
  $iterator = new ParserCSVIterator(realpath($batch
    ->getFilePath()));
  $source_config = $source
    ->getConfigFor($this);
  $parser = new ParserCSV();
  $delimiter = $source_config['delimiter'] == 'TAB' ? "\t" : $source_config['delimiter'];
  $parser
    ->setDelimiter($delimiter);
  if (empty($source_config['no_headers'])) {

    // Get first line and use it for column names, convert them to lower case.
    $header = $this
      ->parseHeader($parser, $iterator);
    if (!$header) {
      return;
    }
    $parser
      ->setColumnNames($header);
  }

  // Populate batch.
  $batch->items = $this
    ->parseItems($parser, $iterator);
}