<?php
namespace App\Utils\CSV\Reader; class Reader extends \App\Utils\CSV\Reader\AbstractReader { protected $fileHandle = null; public function __construct() { parent::__construct(); $this->options['delimiter'] = ','; $this->options['enclosure'] = '"'; $this->options['escape'] = '\\'; } public function setDelimiter(string $value) { return $this->setOption('delimiter', $value); } public function setTextEnclosure(string $value) { return $this->setOption('enclosure', $value); } public function setTextEscape(string $value) { return $this->setOption('escape', $value); } protected function _openFile($file) { if ($file) { $this->fileHandle = fopen($file, "rt"); if (!$this->fileHandle) { throw new \Exception\IO\Base("Cannot open input file[2]"); } } else { throw new \Exception\IO\Base("Cannot open input file[1]"); } } public function _closeFile() { if ($this->fileHandle) { fclose($this->fileHandle); } $this->fileHandle = null; } protected function _next() { $this->currentLineIndex++; $row = null; $rawRow = fgetcsv($this->fileHandle, 0, $this->options['delimiter'], $this->options['enclosure'], $this->options['escape']); if ($rawRow!==false) { $row = new \App\Utils\CSV\Reader\Row($rawRow, $this); return $row; } return null; } } 