fieldDelimiter = $fieldDelimiter; return $this; } /** * Sets the field enclosure for the CSV * * @param string $fieldEnclosure Character that enclose fields * @return CSV */ public function setFieldEnclosure($fieldEnclosure) { $this->fieldEnclosure = $fieldEnclosure; return $this; } /** * Opens the CSV streamer and makes it ready to accept data. * * @return void */ protected function openWriter() { // Adds UTF-8 BOM for Unicode compatibility $this->globalFunctionsHelper->fputs($this->filePointer, self::UTF8_BOM); } /** * Adds data to the currently opened writer. * * @param array $dataRow Array containing data to be written. * Example $dataRow = ['data1', 1234, null, '', 'data5']; * @return void * @throws \Box\Spout\Common\Exception\IOException If unable to write data */ protected function addRowToWriter(array $dataRow) { $wasWriteSuccessful = $this->globalFunctionsHelper->fputcsv($this->filePointer, $dataRow, $this->fieldDelimiter, $this->fieldEnclosure); if ($wasWriteSuccessful === false) { throw new IOException('Unable to write data'); } $this->lastWrittenRowIndex++; if ($this->lastWrittenRowIndex % self::FLUSH_THRESHOLD === 0) { $this->globalFunctionsHelper->fflush($this->filePointer); } } /** * Closes the CSV streamer, preventing any additional writing. * If set, sets the headers and redirects output to the browser. * * @return void */ protected function closeWriter() { if ($this->filePointer) { $this->globalFunctionsHelper->fclose($this->filePointer); } $this->lastWrittenRowIndex = 0; } }