You are here

public static function CsvParser::createFromFilePath in Feeds 8.3

Creates a CsvParser object from a file path.

Parameters

string $filepath: The file path.

Return value

\Drupal\feeds\Component\CsvParser A new CsvParser object.

2 calls to CsvParser::createFromFilePath()
CsvParserTest::testCsvParsing in tests/src/Unit/Component/CsvParserTest.php
Basic test for parsing CSV.
CsvParserTest::testInvalidFilePath in tests/src/Unit/Component/CsvParserTest.php
Tries to create a CsvParser instance with an invalid file path.

File

src/Component/CsvParser.php, line 83

Class

CsvParser
Parses an RFC 4180 style CSV file.

Namespace

Drupal\feeds\Component

Code

public static function createFromFilePath($filepath) {
  if (!is_file($filepath) || !is_readable($filepath)) {
    throw new \InvalidArgumentException('$filepath must exist and be readable.');
  }
  $previous = ini_set('auto_detect_line_endings', '1');
  $handle = fopen($filepath, 'rb');
  ini_set('auto_detect_line_endings', $previous);
  return new static($handle);
}