Commit ae0c837d63a270de9474a3e6223dd31a676d2288
1 parent
aaa56cf3
Exists in
master
and in
1 other branch
versão 0.15.1
Showing
1 changed file
with
46 additions
and
0 deletions
Show diff stats
vendor/ddeboer/data-import/src/Ddeboer/DataImport/Writer/CsvWriter.php
0 → 100644
... | ... | @@ -0,0 +1,46 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace Ddeboer\DataImport\Writer; | |
4 | + | |
5 | +/** | |
6 | + * Writes to a CSV file | |
7 | + * | |
8 | + */ | |
9 | +class CsvWriter extends AbstractWriter | |
10 | +{ | |
11 | + private $delimiter = ';'; | |
12 | + private $enclosure = '"'; | |
13 | + | |
14 | + /** | |
15 | + * Constructor | |
16 | + * | |
17 | + * @param \SplFileObject $file CSV file | |
18 | + * @param string $mode See http://php.net/manual/en/function.fopen.php | |
19 | + * @param string $delimiter The delimiter | |
20 | + * @param string $enclosure The enclosure | |
21 | + */ | |
22 | + public function __construct(\SplFileObject $file, $mode = 'w', $delimiter = ';', $enclosure = '"') | |
23 | + { | |
24 | + $this->fp = fopen($file->getPathname(), $mode); | |
25 | + $this->delimiter = $delimiter; | |
26 | + $this->enclosure = $enclosure; | |
27 | + } | |
28 | + | |
29 | + /** | |
30 | + * {@inheritdoc} | |
31 | + */ | |
32 | + public function writeItem(array $item) | |
33 | + { | |
34 | + fputcsv($this->fp, $item, $this->delimiter, $this->enclosure); | |
35 | + | |
36 | + return $this; | |
37 | + } | |
38 | + | |
39 | + /** | |
40 | + * {@inheritdoc} | |
41 | + */ | |
42 | + public function finish() | |
43 | + { | |
44 | + fclose($this->fp); | |
45 | + } | |
46 | +} | ... | ... |