1 | <?php |
||
22 | class CsvFormatter implements FormatterInterface |
||
23 | { |
||
24 | use RowProcessor; |
||
25 | use InvokeFormatter; |
||
26 | |||
27 | /** @var CsvFormatInterface */ |
||
28 | private $csvFormat; |
||
29 | /** @var string[] */ |
||
30 | private $escapeChars; |
||
31 | /** @var string[] */ |
||
32 | private $replaceChars; |
||
33 | /** @var string */ |
||
34 | private $initial; |
||
35 | /** @var bool */ |
||
36 | private $first = true; |
||
37 | |||
38 | /** |
||
39 | * @param CsvFormatInterface $csvFormat |
||
40 | */ |
||
41 | 21 | public function __construct(CsvFormatInterface $csvFormat) |
|
53 | |||
54 | /** |
||
55 | * Build replacements to perform for each entry |
||
56 | */ |
||
57 | 21 | private function buildReplacements() |
|
83 | |||
84 | /** |
||
85 | * @param array $data |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | 14 | public function format(array $data) |
|
110 | |||
111 | /** |
||
112 | * @param string $string |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 14 | protected function escape($string) |
|
120 | |||
121 | /** |
||
122 | * @param string $string |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | 18 | private function encode($string) |
|
130 | |||
131 | /** |
||
132 | * Return an initial block if required |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | 6 | public function getInitialBlock() |
|
144 | |||
145 | /** |
||
146 | * Get a separator between each row |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | 10 | public function getRowSeparator() |
|
154 | |||
155 | /** |
||
156 | * Return a closing block if required |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | 6 | public function getClosingBlock() |
|
164 | } |
||
165 |