Skip to content

Commit

Permalink
feat(): add CsvWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejpeters authored Aug 12, 2016
1 parent 992d8b0 commit fe15f02
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions CsvWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace boundstate\importexport;

/**
* Writes CSV files.
* @package boundstate\importexport
*/
class CsvWriter extends BaseWriter
{
/**
* Writes to a CSV file.
* @return string filename
*/
public function write() {
$exporter = $this->source;
$filename = \Yii::$app->runtimePath . '/' . uniqid() . '.csv';

$fp = fopen($filename, 'w');

foreach ($exporter->export() as $rowNum => $row) {
fputcsv($fp, $row);
}

return $filename;
}
}

0 comments on commit fe15f02

Please sign in to comment.