1 | <?php |
||
15 | class Writer extends AbstractWriter |
||
16 | { |
||
17 | /** Number of rows to write before flushing */ |
||
18 | const FLUSH_THRESHOLD = 500; |
||
19 | |||
20 | /** @var string Content-Type value for the header */ |
||
21 | protected static $headerContentType = 'text/csv; charset=UTF-8'; |
||
22 | |||
23 | /** @var string Defines the character used to delimit fields (one character only) */ |
||
24 | protected $fieldDelimiter = ','; |
||
25 | |||
26 | /** @var string Defines the character used to enclose fields (one character only) */ |
||
27 | protected $fieldEnclosure = '"'; |
||
28 | |||
29 | /** @var int */ |
||
30 | protected $lastWrittenRowIndex = 0; |
||
31 | |||
32 | /** @var bool */ |
||
33 | protected $shouldAddBOM = true; |
||
34 | |||
35 | /** |
||
36 | * Sets the field delimiter for the CSV |
||
37 | * |
||
38 | * @api |
||
39 | 18 | * @param string $fieldDelimiter Character that delimits fields |
|
40 | * @return Writer |
||
41 | 18 | */ |
|
42 | 18 | public function setFieldDelimiter($fieldDelimiter) |
|
47 | |||
48 | /** |
||
49 | * Sets the field enclosure for the CSV |
||
50 | * |
||
51 | * @api |
||
52 | 18 | * @param string $fieldEnclosure Character that enclose fields |
|
53 | * @return Writer |
||
54 | 18 | */ |
|
55 | 18 | public function setFieldEnclosure($fieldEnclosure) |
|
60 | |||
61 | /** |
||
62 | * Set if a BOM has to be added to the file |
||
63 | 18 | * |
|
64 | * @param bool $shouldAddBOM |
||
65 | * |
||
66 | 18 | * @return Writer |
|
67 | 18 | */ |
|
68 | public function setShouldAddBOM($shouldAddBOM) |
||
69 | { |
||
70 | $this->shouldAddBOM = (bool) $shouldAddBOM; |
||
71 | return $this; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Opens the CSV streamer and makes it ready to accept data. |
||
76 | * |
||
77 | * @return void |
||
78 | 18 | */ |
|
79 | protected function openWriter() |
||
86 | 18 | ||
87 | /** |
||
88 | * Adds data to the currently opened writer. |
||
89 | 18 | * |
|
90 | * @param array $dataRow Array containing data to be written. |
||
91 | * Example $dataRow = ['data1', 1234, null, '', 'data5']; |
||
92 | * @param \Box\Spout\Writer\Style\Style $style Ignored here since CSV does not support styling. |
||
93 | * @return void |
||
94 | * @throws \Box\Spout\Common\Exception\IOException If unable to write data |
||
95 | */ |
||
96 | protected function addRowToWriter(array $dataRow, $style) |
||
108 | |||
109 | /** |
||
110 | * Closes the CSV streamer, preventing any additional writing. |
||
111 | * If set, sets the headers and redirects output to the browser. |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | protected function closeWriter() |
||
119 | } |
||
120 |