1 | <?php |
||
7 | class CsvFormat implements CsvFormatInterface |
||
8 | { |
||
9 | use GetOptionTrait; |
||
10 | |||
11 | const DEFAULT_DELIMITER = ','; |
||
12 | const DEFAULT_NULL_OUTPUT = '\\N'; |
||
13 | const DEFAULT_INCLUDE_HEADERS = true; |
||
14 | const DEFAULT_LINE_TERMINATOR = "\n"; |
||
15 | const DEFAULT_QUOTE_CHARACTER = '"'; |
||
16 | |||
17 | const OPTION_DELIMITER = 'delimiter'; |
||
18 | const OPTION_NULL_OUTPUT = 'nullOutput'; |
||
19 | const OPTION_INCLUDE_HEADERS = 'includeHeaders'; |
||
20 | const OPTION_LINE_TERMINATOR = 'lineTerminator'; |
||
21 | const OPTION_QUOTE_CHARACTER = 'quoteCharacter'; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $delimiter; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $quoteCharacter; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $nullOutput; |
||
37 | |||
38 | /** |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected $includeHeaders; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $lineTerminator; |
||
47 | |||
48 | /** |
||
49 | * @param array $options -delimiter <string> (Default: ,) Character to use between fields |
||
50 | * -quoteCharacter <string> (Default: ") |
||
51 | * -nullOutput <string> (Default: \N) |
||
52 | * -includeHeaders <bool> (Default: true) |
||
53 | * -lineTerminator <string> (Default: \n) [Not current implemented] |
||
54 | */ |
||
55 | 10 | public function __construct($options = []) |
|
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | 7 | public function getDelimiter() |
|
72 | |||
73 | /** |
||
74 | * @param string $delimiter |
||
75 | * |
||
76 | * @return CsvFormat |
||
77 | */ |
||
78 | 3 | public function setDelimiter($delimiter) |
|
83 | |||
84 | /** |
||
85 | * @return bool |
||
86 | */ |
||
87 | 6 | public function hasQuotes() |
|
88 | { |
||
89 | 6 | return $this->quoteCharacter <> ''; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return string |
||
94 | */ |
||
95 | 6 | public function getNullOutput() |
|
99 | |||
100 | /** |
||
101 | * @param string $nullOutput |
||
102 | * |
||
103 | * @return CsvFormat |
||
104 | */ |
||
105 | 2 | public function setNullOutput($nullOutput) |
|
110 | |||
111 | /** |
||
112 | * @return bool |
||
113 | */ |
||
114 | 6 | public function hasHeaders() |
|
115 | { |
||
116 | 6 | return $this->includeHeaders; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * @param bool $includeHeaders |
||
121 | * |
||
122 | * @return CsvFormat |
||
123 | */ |
||
124 | 2 | public function setHeaders($includeHeaders) |
|
125 | { |
||
126 | 2 | $this->includeHeaders = $includeHeaders; |
|
127 | 2 | return $this; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * @return string |
||
132 | */ |
||
133 | 6 | public function getLineTerminator() |
|
137 | |||
138 | /** |
||
139 | * @param string $lineTerminator |
||
140 | * |
||
141 | * @return CsvFormat |
||
142 | */ |
||
143 | 2 | public function setLineTerminator($lineTerminator) |
|
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | 6 | public function getQuoteCharacter() |
|
156 | |||
157 | /** |
||
158 | * @param string $quoteCharacter |
||
159 | * |
||
160 | * @return CsvFormat |
||
161 | */ |
||
162 | 2 | public function setQuoteCharacter($quoteCharacter) |
|
167 | |||
168 | /** |
||
169 | * Type type of file format (defined in FileFormatType::) |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | 1 | public function getType() |
|
177 | } |
||
178 |