* @package Mammut\IO */ class CSVFile extends Textfile { const _VERSION_ = '0.5.0.2'; protected $delimiter = ','; protected $enclosure = '"'; /** * Create a new CSV file object * * @param string $path * the path of the object */ public function __construct($path, $delimiter = ',' , $enclosure = '"', $ro = false) { parent::__construct($path, $ro); $this->delimiter = $delimiter; $this->enclosure = $enclosure; } public function readCSV() { if (!$this->isOpen()) throw new IllegalStateException("file not opened"); if ($this->isEOF()) return false; $this->skipBOM(); // TODO: support other delimiter and enclosure // array fgetcsv ( resource $handle [, int $length = 0 [, string $delimiter = ',' [, string $enclosure = '"' [, string $escape = '\\' ]]]] ) $data = fgetcsv($this->fp, 0, $this->delimiter, $this->enclosure); return $data; } public function writeCSV(array $data) { fputcsv($this->fp, $data, $this->delimiter, $this->enclosure); } }