1 | <?php |
||
22 | class CsvFormatter implements FormatterInterface |
||
23 | { |
||
24 | use RowProcessor; |
||
25 | use InvokeFormatter; |
||
26 | |||
27 | /** |
||
28 | * @var CsvFormatInterface |
||
29 | */ |
||
30 | private $csvFormat; |
||
31 | |||
32 | /** |
||
33 | * @var string[] |
||
34 | */ |
||
35 | private $escapeChars; |
||
36 | |||
37 | /** |
||
38 | * @var string[] |
||
39 | */ |
||
40 | private $replaceChars; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $initial; |
||
46 | |||
47 | /** |
||
48 | * @param CsvFormatInterface $csvFormat |
||
49 | */ |
||
50 | 15 | public function __construct(CsvFormatInterface $csvFormat) |
|
62 | |||
63 | /** |
||
64 | * Build replacements to perform for each entry |
||
65 | */ |
||
66 | 15 | private function buildReplacements() |
|
92 | |||
93 | /** |
||
94 | * @param array $data |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | 11 | public function format(array $data) |
|
112 | |||
113 | /** |
||
114 | * @param string $string |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 11 | protected function escape($string) |
|
122 | |||
123 | /** |
||
124 | * @param string $string |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | 12 | private function encode($string) |
|
132 | |||
133 | /** |
||
134 | * Return an initial block if required |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | 5 | public function getInitialBlock() |
|
142 | |||
143 | /** |
||
144 | * Get a separator between each row |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | 4 | public function getRowSeparator() |
|
152 | |||
153 | /** |
||
154 | * Return a closing block if required |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | 5 | public function getClosingBlock() |
|
162 | } |
||
163 |