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_HEADERS = 1; |
||
25 | const DEFAULT_LINE_TERMINATOR = "\n"; |
||
26 | const DEFAULT_QUOTE_CHARACTER = '"'; |
||
27 | const DEFAULT_ESCAPE = '\\'; |
||
28 | const DEFAULT_LIMIT = -1; |
||
29 | const DEFAULT_DOUBLE_QUOTE = false; |
||
30 | |||
31 | const OPTION_DELIMITER = 'delimiter'; |
||
32 | const OPTION_NULL_OUTPUT = 'nullOutput'; |
||
33 | const OPTION_HEADERS = 'headers'; |
||
34 | const OPTION_LINE_TERMINATOR = 'lineTerminator'; |
||
35 | const OPTION_QUOTE_CHARACTER = 'quoteCharacter'; |
||
36 | const OPTION_ESCAPE = 'escape'; |
||
37 | const OPTION_LIMIT = 'limit'; |
||
38 | const OPTION_DOUBLE_QUOTE = 'doubleQuote'; |
||
39 | |||
40 | /** @var string */ |
||
41 | protected $delimiter; |
||
42 | /** @var string */ |
||
43 | protected $quoteCharacter; |
||
44 | /** @var string */ |
||
45 | protected $nullOutput; |
||
46 | /** @var int */ |
||
47 | protected $headers; |
||
48 | /** @var string */ |
||
49 | protected $lineTerminator; |
||
50 | /** @var bool */ |
||
51 | protected $nullQuotes; |
||
52 | /** @var string */ |
||
53 | protected $escape; |
||
54 | /** @var int */ |
||
55 | protected $limit; |
||
56 | /** @var bool */ |
||
57 | protected $doubleQuote; |
||
58 | |||
59 | /** |
||
60 | * @param array $options -delimiter <string> (Default: ,) Character to use between fields |
||
61 | * -quoteCharacter <string> (Default: ") |
||
62 | * -nullOutput <string> (Default: \N) |
||
63 | * -headers <int> (Default: 1) |
||
64 | * -lineTerminator <string> (Default: \n) |
||
65 | * |
||
66 | */ |
||
67 | 16 | public function __construct(array $options = []) |
|
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | 25 | public function getDelimiter() |
|
87 | |||
88 | /** |
||
89 | * @param string $delimiter |
||
90 | * |
||
91 | * @return static |
||
92 | */ |
||
93 | 3 | public function setDelimiter($delimiter) |
|
98 | |||
99 | /** |
||
100 | * @return bool |
||
101 | */ |
||
102 | 20 | public function hasQuotes() |
|
106 | |||
107 | /** |
||
108 | * @return string |
||
109 | */ |
||
110 | 15 | public function getNullOutput() |
|
114 | |||
115 | /** |
||
116 | * @param string $nullOutput |
||
117 | * |
||
118 | * @return static |
||
119 | */ |
||
120 | 2 | public function setNullOutput($nullOutput) |
|
125 | |||
126 | /** |
||
127 | * @return bool |
||
128 | */ |
||
129 | 11 | public function hasHeaders() |
|
133 | |||
134 | /** |
||
135 | * @param int $headers |
||
136 | * |
||
137 | * @return static |
||
138 | */ |
||
139 | 2 | public function setHeaders($headers) |
|
144 | |||
145 | /** |
||
146 | * @return int |
||
147 | */ |
||
148 | 6 | public function getHeaders() |
|
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | 15 | public function getLineTerminator() |
|
160 | |||
161 | /** |
||
162 | * @param string $lineTerminator |
||
163 | * |
||
164 | * @return static |
||
165 | */ |
||
166 | 2 | public function setLineTerminator($lineTerminator) |
|
171 | |||
172 | /** |
||
173 | * @note Csv Rfc spec defines escaping of quotes to be done using double quotes `""` |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | 24 | public function getQuoteCharacter() |
|
181 | |||
182 | /** |
||
183 | * @param string $quoteCharacter |
||
184 | * |
||
185 | * @return static |
||
186 | */ |
||
187 | 2 | public function setQuoteCharacter($quoteCharacter) |
|
192 | |||
193 | /** |
||
194 | * Type type of file format (defined in FileFormatType::) |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | 3 | public function getType() |
|
202 | |||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | 22 | public function getEscapeCharacter() |
|
210 | |||
211 | /** |
||
212 | * @param string $escape |
||
213 | * |
||
214 | * @return static |
||
215 | */ |
||
216 | 1 | public function setEscapeCharacter($escape) |
|
221 | |||
222 | /** |
||
223 | * @return bool |
||
224 | */ |
||
225 | 3 | public function hasEscapeCharacter() |
|
229 | |||
230 | /** |
||
231 | * Get the limit that should be returned (-1 for no limit) |
||
232 | * |
||
233 | * @return int |
||
234 | */ |
||
235 | 8 | public function getLimit() |
|
239 | |||
240 | /** |
||
241 | * Set the limit of the number of items to be returned (-1 for not limit) |
||
242 | * |
||
243 | * @param int $limit |
||
244 | * |
||
245 | * @return static |
||
246 | */ |
||
247 | 1 | public function setLimit($limit) |
|
252 | |||
253 | /** |
||
254 | * @return bool |
||
255 | */ |
||
256 | 19 | public function isDoubleQuote() |
|
260 | |||
261 | /** |
||
262 | * @param bool $doubleQuote |
||
263 | * |
||
264 | * @return static |
||
265 | */ |
||
266 | 1 | public function setDoubleQuote($doubleQuote) |
|
271 | } |
||
272 |