Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV files: added possibility to select PHP input file mode #14610

Merged
merged 3 commits into from
May 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions lib/internal/Magento/Framework/File/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,37 @@ public function getDataPairs($file, $keyIndex = 0, $valueIndex = 1)
/**
* Saving data row array into file
*
* @param string $file
* @param array $data
* @return $this
* @param string $file
* @param array $data
* @return $this
* @throws \Magento\Framework\Exception\FileSystemException
* @deprecated
* @see appendData
*/
public function saveData($file, $data)
{
$fh = fopen($file, 'w');
return $this->appendData($file, $data, 'w');
}

/**
* Replace the saveData method by allowing to select the input mode
*
* @param string $file
* @param array $data
* @param string $mode
*
* @return $this
*
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function appendData($file, $data, $mode = 'w')
{
$fileHandler = fopen($file, $mode);
foreach ($data as $dataRow) {
$this->file->filePutCsv($fh, $dataRow, $this->_delimiter, $this->_enclosure);
$this->file->filePutCsv($fileHandler, $dataRow, $this->_delimiter, $this->_enclosure);
}
fclose($fh);
fclose($fileHandler);

return $this;
}
}