Skip to content

Commit

Permalink
Merge 984be6c into 0a1b535
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesvdvreken committed Feb 11, 2016
2 parents 0a1b535 + 984be6c commit c133730
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Modifier/RowFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function clearValidators()
*
* @return array
*/
protected function formatRow(array $row)
protected function formatRow($row)
{
foreach ($this->formatters as $formatter) {
$row = call_user_func($formatter, $row);
Expand Down
22 changes: 19 additions & 3 deletions src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected function __construct($path, $open_mode = 'r+')
{
parent::__construct($path, $open_mode);
static::initFputcsv();
$this->addDefaultFormatters();
}

/**
Expand Down Expand Up @@ -110,9 +111,6 @@ public function insertAll($rows)
*/
public function insertOne($row)
{
if (!is_array($row)) {
$row = str_getcsv($row, $this->delimiter, $this->enclosure, $this->escape);
}
$row = $this->formatRow($row);
$this->validateRow($row);

Expand Down Expand Up @@ -146,6 +144,24 @@ protected function getFputcsvParameters(array $fields)
return $parameters;
}

/**
* Adds default formatters.
*
* @return static
*/
private function addDefaultFormatters()
{
$this->addFormatter(function ($row) {
if (is_array($row)) {
return $row;
}

return str_getcsv($row, $this->delimiter, $this->enclosure, $this->escape);
});

return $this;
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit c133730

Please sign in to comment.