1 | <?php |
||
12 | class CsvWriter |
||
13 | { |
||
14 | /** |
||
15 | * @var resource |
||
16 | */ |
||
17 | private $out; |
||
18 | |||
19 | /** |
||
20 | * @var string|null |
||
21 | */ |
||
22 | private $encodeTo; |
||
23 | |||
24 | 11 | public function __construct($encodeTo = null) |
|
25 | { |
||
26 | 11 | $this->out = fopen('php://output', 'wt'); |
|
27 | |||
28 | 11 | if (null !== $encodeTo && 'UTF-8' !== strtoupper($encodeTo)) { |
|
29 | 5 | $this->encodeTo = $encodeTo; |
|
30 | } |
||
31 | 11 | } |
|
32 | |||
33 | 11 | public function __destruct() |
|
37 | |||
38 | /** |
||
39 | * Writes the csv to stdout. |
||
40 | * |
||
41 | * @param array|\Traversable $row |
||
42 | */ |
||
43 | 11 | public function writeRow($row) |
|
59 | |||
60 | /** |
||
61 | * Returns the formatted cell. |
||
62 | * |
||
63 | * @param string $cell |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | 10 | private function formatCell($cell) |
|
77 | } |
||
78 |