1 | <?php |
||
18 | class CsvFormat implements CsvFormatInterface |
||
19 | { |
||
20 | use GetOptionTrait; |
||
21 | |||
22 | const DEFAULT_DELIMITER = ','; |
||
23 | const DEFAULT_NULL_OUTPUT = '\\N'; |
||
24 | const DEFAULT_HEADER_ROW = -1; |
||
25 | const DEFAULT_DATA_START = 1; |
||
26 | const DEFAULT_LINE_TERMINATOR = "\n"; |
||
27 | const DEFAULT_QUOTE_CHARACTER = '"'; |
||
28 | const DEFAULT_ESCAPE = '\\'; |
||
29 | const DEFAULT_LIMIT = -1; |
||
30 | const DEFAULT_DOUBLE_QUOTE = false; |
||
31 | |||
32 | const OPTION_DELIMITER = 'delimiter'; |
||
33 | const OPTION_NULL_OUTPUT = 'nullOutput'; |
||
34 | const OPTION_HEADER_ROW = 'headerRow'; |
||
35 | const OPTION_DATA_START = 'dataStart'; |
||
36 | const OPTION_LINE_TERMINATOR = 'lineTerminator'; |
||
37 | const OPTION_QUOTE_CHARACTER = 'quoteCharacter'; |
||
38 | const OPTION_ESCAPE = 'escape'; |
||
39 | const OPTION_LIMIT = 'limit'; |
||
40 | const OPTION_DOUBLE_QUOTE = 'doubleQuote'; |
||
41 | |||
42 | /** @var string */ |
||
43 | protected $delimiter; |
||
44 | /** @var string */ |
||
45 | protected $quoteCharacter; |
||
46 | /** @var string */ |
||
47 | protected $nullOutput; |
||
48 | /** @var int */ |
||
49 | protected $headerRow; |
||
50 | /** @var string */ |
||
51 | protected $lineTerminator; |
||
52 | /** @var bool */ |
||
53 | protected $nullQuotes; |
||
54 | /** @var string */ |
||
55 | protected $escape; |
||
56 | /** @var int */ |
||
57 | protected $limit; |
||
58 | /** @var bool */ |
||
59 | protected $doubleQuote; |
||
60 | /** @var int */ |
||
61 | protected $dataStart; |
||
62 | |||
63 | /** |
||
64 | * @param array $options -delimiter <string> (Default: ,) Character to use between fields |
||
65 | * -quoteCharacter <string> (Default: ") |
||
66 | * -nullOutput <string> (Default: \N) |
||
67 | 16 | * -headerRow <int> (Default: -1) -1 for no header row. (1 is the first line of the file) |
|
68 | * -dataStart <int> (Default: 1) The line where the data starts (1 is the first list of the |
||
69 | 16 | * file) |
|
70 | 16 | * -lineTerminator <string> (Default: \n) |
|
71 | 16 | * -escape <string> (Default: \\) Character to use for escaping |
|
72 | 16 | * -limit <int> Total number of data rows to return |
|
73 | 16 | * -doubleQuote <bool> instances of quote in fields are indicated by a double quote |
|
74 | 16 | */ |
|
75 | 16 | public function __construct(array $options = []) |
|
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | */ |
||
92 | public function getDelimiter() |
||
96 | 3 | ||
97 | /** |
||
98 | * @param string $delimiter |
||
99 | * |
||
100 | * @return static |
||
101 | */ |
||
102 | 20 | public function setDelimiter($delimiter) |
|
107 | |||
108 | /** |
||
109 | * @return bool |
||
110 | 15 | */ |
|
111 | public function hasQuotes() |
||
115 | |||
116 | /** |
||
117 | * @return string |
||
118 | */ |
||
119 | public function getNullOutput() |
||
123 | 2 | ||
124 | /** |
||
125 | * @param string $nullOutput |
||
126 | * |
||
127 | * @return static |
||
128 | */ |
||
129 | 11 | public function setNullOutput($nullOutput) |
|
134 | |||
135 | /** |
||
136 | * @return bool |
||
137 | */ |
||
138 | public function hasHeaderRow() |
||
142 | 2 | ||
143 | /** |
||
144 | * @param int $headerRow |
||
145 | * |
||
146 | * @return static |
||
147 | */ |
||
148 | 6 | public function setHeaderRow($headerRow) |
|
153 | |||
154 | /** |
||
155 | * @return int |
||
156 | 15 | */ |
|
157 | public function getHeaderRow() |
||
161 | |||
162 | /** |
||
163 | * @param int $row |
||
164 | * |
||
165 | * @return static |
||
166 | 2 | */ |
|
167 | public function setDataStart($row) |
||
172 | |||
173 | /** |
||
174 | * @return int |
||
175 | */ |
||
176 | public function getDataStart() |
||
183 | |||
184 | /** |
||
185 | * @return string |
||
186 | */ |
||
187 | 2 | public function getLineTerminator() |
|
191 | |||
192 | /** |
||
193 | * @param string $lineTerminator |
||
194 | * |
||
195 | * @return static |
||
196 | */ |
||
197 | public function setLineTerminator($lineTerminator) |
||
202 | |||
203 | /** |
||
204 | * @note Csv Rfc spec defines escaping of quotes to be done using double quotes `""` |
||
205 | * |
||
206 | 22 | * @return string |
|
207 | */ |
||
208 | 22 | public function getQuoteCharacter() |
|
212 | |||
213 | /** |
||
214 | * @param string $quoteCharacter |
||
215 | * |
||
216 | 1 | * @return static |
|
217 | */ |
||
218 | 1 | public function setQuoteCharacter($quoteCharacter) |
|
223 | |||
224 | /** |
||
225 | 3 | * Type type of file format (defined in FileFormatType::) |
|
226 | * |
||
227 | 3 | * @return string |
|
228 | */ |
||
229 | public function getType() |
||
233 | |||
234 | /** |
||
235 | 8 | * @return string |
|
236 | */ |
||
237 | 8 | public function getEscapeCharacter() |
|
241 | |||
242 | /** |
||
243 | * @param string $escape |
||
244 | * |
||
245 | * @return static |
||
246 | */ |
||
247 | 1 | public function setEscapeCharacter($escape) |
|
252 | |||
253 | /** |
||
254 | * @return bool |
||
255 | */ |
||
256 | 19 | public function hasEscapeCharacter() |
|
260 | |||
261 | /** |
||
262 | * Get the limit that should be returned (-1 for no limit) |
||
263 | * |
||
264 | * @return int |
||
265 | */ |
||
266 | 1 | public function getLimit() |
|
270 | |||
271 | /** |
||
272 | * Set the limit of the number of items to be returned (-1 for not limit) |
||
273 | * |
||
274 | * @param int $limit |
||
275 | * |
||
276 | * @return static |
||
277 | */ |
||
278 | public function setLimit($limit) |
||
283 | |||
284 | /** |
||
285 | * @return bool |
||
286 | */ |
||
287 | public function isDoubleQuote() |
||
291 | |||
292 | /** |
||
293 | * @param bool $doubleQuote |
||
294 | * |
||
295 | * @return static |
||
296 | */ |
||
297 | public function setDoubleQuote($doubleQuote) |
||
302 | } |
||
303 |