<?php
namespace App\Utils\CSV\Writer; class BufferedWriter extends Writer { protected $headerRows = []; protected $rows = []; public function fromArray($rows) { $this->rows = $rows; return $this; } public function appendRow($row) { $this->rows[] = $row; return $this; } public function appendHeaderRow($row) { $this->headerRows[] = $row; return $this; } public function resetHeader() { $this->headerRows = []; return $this; } public function save($file) { $fp = fopen($file, "w"); foreach ($this->headerRows as $row) { $this->fputcsv($fp, $row, $this->options['delimiter'], $this->options['enclosure'], $this->options['escape_char']); } foreach ($this->rows as $row) { $this->fputcsv($fp, $row, $this->options['delimiter'], $this->options['enclosure'], $this->options['escape_char']); } fclose($fp); } } 