/** * @param string $filePath Path to the csv file to read from * @param string $delimiter The delimiter for the csv file * @param string $enclosure The enclosure for the csv file */ public function __construct($filePath, $delimiter = ',', $enclosure = '"') { if (!is_file($filePath)) { throw new LogicException(sprintf('The file %s does not exist. \\Plum\\PlumCsv\\CsvReader needs an existing csv to work with', $filePath)); } $this->csv = Reader::createFromPath($filePath); $this->csv->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY); $this->csv->setDelimiter($delimiter); $this->csv->setEnclosure($enclosure); }
/** * * @return Reader */ public function getReader() { if (strlen($this->csvFileContent) === 0) { $this->loadCsvFile(); } if (is_null($this->reader)) { $this->reader = Reader::createFromString($this->getCsvFileContent()); $this->reader->setDelimiter($this->delimiter); } return $this->reader; }