1 | <?php |
||
8 | class Writer extends AbstractCsv |
||
9 | { |
||
10 | /** @var string */ |
||
11 | protected $fopenMode = 'w+'; |
||
12 | /** @var string */ |
||
13 | protected $lineEnding = "\r\n"; |
||
14 | /** @var int */ |
||
15 | protected $bytesWritten = 0; |
||
16 | |||
17 | public static function write($file, $data) |
||
23 | |||
24 | /** |
||
25 | * @inheritDoc |
||
26 | */ |
||
27 | 1 | public function closeFileHandle() |
|
33 | |||
34 | /** |
||
35 | * Sets headers and all rows on the CSV file and |
||
36 | * then closes the file handle. |
||
37 | * |
||
38 | * @param $data |
||
39 | */ |
||
40 | public function setData($data) |
||
48 | |||
49 | /** |
||
50 | * @param array $headers |
||
51 | */ |
||
52 | public function setHeaders(array $headers) |
||
59 | |||
60 | /** |
||
61 | * Adds multiple rows of data to the CSV file. |
||
62 | * |
||
63 | * @param array $rows |
||
64 | */ |
||
65 | public function addRows($rows) |
||
71 | |||
72 | /** |
||
73 | * Adds a row of data to the CSV file. |
||
74 | * |
||
75 | * @param array $row Row of data to add to the file. |
||
76 | * |
||
77 | * @return bool Whether the row was written to the file. |
||
78 | */ |
||
79 | public function addRow($row) |
||
96 | |||
97 | /** |
||
98 | * Returns the line ending delimiter used to separate rows |
||
99 | * in the CSV file. |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | public function getLineEnding() |
||
107 | |||
108 | /** |
||
109 | * Sets the line ending delimiter used to separate rows |
||
110 | * in the CSV file. |
||
111 | * |
||
112 | * @param string $lineEnding |
||
113 | * |
||
114 | * @return Writer |
||
115 | */ |
||
116 | public function setLineEnding($lineEnding) |
||
122 | |||
123 | /** |
||
124 | * Returns a string representation of a row to be written |
||
125 | * as a line in a CSV file. |
||
126 | * |
||
127 | * @param array $row |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | protected function getCsvString($row) |
||
143 | |||
144 | /** |
||
145 | * Trims the line ending delimiter from the end of the CSV file. |
||
146 | * RFC-4180 states CSV files should not contain a trailing new line. |
||
147 | */ |
||
148 | 1 | protected function trimTrailingLineEnding() |
|
162 | |||
163 | /** |
||
164 | * Escapes the enclosure character recursively. |
||
165 | * RFC-4180 states the enclosure character (usually double quotes) should be |
||
166 | * escaped by itself, so " becomes "". |
||
167 | * |
||
168 | * @param mixed $data Array or string of data to escape. |
||
169 | * |
||
170 | * @return mixed Escaped data |
||
171 | */ |
||
172 | protected function escapeEnclosure($data) |
||
184 | } |
||
185 |