1 | <?php |
||
16 | class HomogeneousCSVWriter extends FileWriter implements ArchivableWriterInterface |
||
17 | { |
||
18 | /** |
||
19 | * @Assert\NotBlank |
||
20 | * @Assert\Choice(choices={",", ";", "|"}, message="The value must be one of , or ; or |") |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $delimiter = ';'; |
||
24 | |||
25 | /** |
||
26 | * @Assert\NotBlank |
||
27 | * @Assert\Choice(choices={"""", "'"}, message="The value must be one of "" or '") |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $enclosure = '"'; |
||
31 | |||
32 | /** @var boolean */ |
||
33 | protected $withHeader = true; |
||
34 | |||
35 | /** @var array */ |
||
36 | private $writtenFiles = []; |
||
37 | |||
38 | /** @var array */ |
||
39 | private $headers; |
||
40 | |||
41 | /** @var resource */ |
||
42 | private $file; |
||
43 | |||
44 | /** |
||
45 | * Sets the csv delimiter character |
||
46 | * |
||
47 | * @param string $delimiter |
||
48 | */ |
||
49 | public function setDelimiter($delimiter) |
||
53 | |||
54 | /** |
||
55 | * Gets the csv delimiter character |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getDelimiter() |
||
63 | |||
64 | /** |
||
65 | * Sets the csv enclosure character |
||
66 | * |
||
67 | * @param string $enclosure |
||
68 | */ |
||
69 | public function setEnclosure($enclosure) |
||
73 | |||
74 | /** |
||
75 | * Gets the csv enclosure character |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | public function getEnclosure() |
||
83 | |||
84 | /** |
||
85 | * Sets whether or not to print a header row into the csv |
||
86 | * |
||
87 | * @param boolean $withHeader |
||
88 | */ |
||
89 | public function setWithHeader($withHeader) |
||
93 | |||
94 | /** |
||
95 | * Gets whether or not to print a header row into the csv |
||
96 | * |
||
97 | * @return boolean |
||
98 | */ |
||
99 | public function isWithHeader() |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function getWrittenFiles() |
||
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | public function initialize() |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function flush() |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | public function getConfigurationFields() |
||
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | public function write(array $items) |
||
180 | |||
181 | /** |
||
182 | * Writes an item in the file |
||
183 | * |
||
184 | * @param array $item |
||
185 | */ |
||
186 | protected function writeItem(array $item) |
||
194 | |||
195 | /** |
||
196 | * Returns a CSV row for an item |
||
197 | * |
||
198 | * @param array $item |
||
199 | * |
||
200 | * @return array |
||
201 | */ |
||
202 | protected function getItemRow(array $item) |
||
211 | |||
212 | /** |
||
213 | * Writes the headers |
||
214 | * |
||
215 | * @param array $csv |
||
216 | */ |
||
217 | protected function writeHeaders() |
||
223 | |||
224 | /** |
||
225 | * Writes a CSV line in the file |
||
226 | * |
||
227 | * @param array $csv |
||
228 | */ |
||
229 | protected function writeLine(array $csv) |
||
233 | } |
||
234 |