Skip to content

Commit fe15f02

Browse files
authored
feat(): add CsvWriter
1 parent 992d8b0 commit fe15f02

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

CsvWriter.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
namespace boundstate\importexport;
3+
4+
/**
5+
* Writes CSV files.
6+
* @package boundstate\importexport
7+
*/
8+
class CsvWriter extends BaseWriter
9+
{
10+
/**
11+
* Writes to a CSV file.
12+
* @return string filename
13+
*/
14+
public function write() {
15+
$exporter = $this->source;
16+
$filename = \Yii::$app->runtimePath . '/' . uniqid() . '.csv';
17+
18+
$fp = fopen($filename, 'w');
19+
20+
foreach ($exporter->export() as $rowNum => $row) {
21+
fputcsv($fp, $row);
22+
}
23+
24+
return $filename;
25+
}
26+
}

0 commit comments

Comments
 (0)