1 | <?php |
||
29 | trait Output |
||
30 | { |
||
31 | /** |
||
32 | * Charset Encoding for the CSV |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $input_encoding = 'UTF-8'; |
||
37 | |||
38 | /** |
||
39 | * The Input file BOM character |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $input_bom; |
||
43 | |||
44 | /** |
||
45 | * The Output file BOM character |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $output_bom = ''; |
||
49 | |||
50 | /** |
||
51 | * Sets the CSV encoding charset |
||
52 | * |
||
53 | * @param string $str |
||
54 | * |
||
55 | * @return static |
||
56 | */ |
||
57 | 6 | public function setInputEncoding($str) |
|
68 | |||
69 | /** |
||
70 | * Sets the CSV encoding charset |
||
71 | * |
||
72 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
73 | * |
||
74 | 3 | * @deprecated deprecated since version 4.1 |
|
75 | * |
||
76 | 3 | * @param string $str |
|
77 | * |
||
78 | * @return static |
||
79 | */ |
||
80 | public function setEncodingFrom($str) |
||
84 | |||
85 | /** |
||
86 | 9 | * Gets the source CSV encoding charset |
|
87 | * |
||
88 | 9 | * @return string |
|
89 | 3 | */ |
|
90 | public function getInputEncoding() |
||
94 | 9 | ||
95 | /** |
||
96 | 9 | * Gets the source CSV encoding charset |
|
97 | * |
||
98 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
99 | * |
||
100 | * @deprecated deprecated since version 4.1 |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 3 | public function getEncodingFrom() |
|
108 | |||
109 | /** |
||
110 | * Sets the BOM sequence to prepend the CSV on output |
||
111 | * |
||
112 | * @param string $str The BOM sequence |
||
113 | * |
||
114 | 51 | * @return static |
|
115 | */ |
||
116 | 51 | public function setOutputBOM($str) |
|
128 | |||
129 | 51 | /** |
|
130 | 34 | * Returns the BOM sequence in use on Output methods |
|
131 | * |
||
132 | 51 | * @return string |
|
133 | */ |
||
134 | public function getOutputBOM() |
||
138 | |||
139 | /** |
||
140 | * Returns the BOM sequence of the given CSV |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getInputBOM() |
||
164 | |||
165 | /** |
||
166 | 18 | * @inheritdoc |
|
167 | */ |
||
168 | 18 | abstract public function getIterator(); |
|
169 | 18 | ||
170 | 18 | /** |
|
171 | 6 | * Outputs all data on the CSV file |
|
172 | 4 | * |
|
173 | 18 | * @param string $filename CSV downloaded name if present adds extra headers |
|
174 | 18 | * |
|
175 | 18 | * @return int Returns the number of characters read from the handle |
|
176 | 18 | * and passed through to the output. |
|
177 | 6 | */ |
|
178 | 4 | public function output($filename = null) |
|
189 | |||
190 | 12 | /** |
|
191 | * Outputs all data from the CSV |
||
192 | 12 | * |
|
193 | 12 | * @return int Returns the number of characters read from the handle |
|
194 | * and passed through to the output. |
||
195 | 12 | */ |
|
196 | protected function fpassthru() |
||
214 | |||
215 | /** |
||
216 | * Retrieves the CSV content |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | public function __toString() |
||
227 | |||
228 | /** |
||
229 | 3 | * @inheritdoc |
|
230 | 3 | */ |
|
231 | public function jsonSerialize() |
||
235 | |||
236 | 3 | /** |
|
237 | * Returns the CSV Iterator |
||
238 | * |
||
239 | * @return Iterator |
||
240 | */ |
||
241 | abstract protected function getQueryIterator(); |
||
242 | |||
243 | /** |
||
244 | * Convert Csv file into UTF-8 |
||
245 | * |
||
246 | 6 | * @param Iterator $iterator |
|
247 | * |
||
248 | 6 | * @return Iterator |
|
249 | 6 | */ |
|
250 | protected function convertToUtf8(Iterator $iterator) |
||
266 | 15 | ||
267 | 15 | /** |
|
268 | 15 | * Returns a HTML table representation of the CSV Table |
|
269 | 15 | * |
|
270 | 15 | * @param string $class_attr optional classname |
|
271 | 15 | * |
|
272 | 15 | * @return string |
|
273 | 15 | */ |
|
274 | 15 | public function toHTML($class_attr = 'table-csv-data') |
|
281 | |||
282 | /** |
||
283 | * Transforms a CSV into a XML |
||
284 | * |
||
285 | * @param string $root_name XML root node name |
||
286 | * @param string $row_name XML row node name |
||
287 | * @param string $cell_name XML cell node name |
||
288 | * |
||
289 | * @return DomDocument |
||
290 | */ |
||
291 | public function toXML($root_name = 'csv', $row_name = 'row', $cell_name = 'cell') |
||
309 | } |
||
310 |