Skip to content

Commit bd82f26

Browse files
ENGCOM-1253: CSV files: added possibility to select PHP input file mode #14610
- Merge Pull Request #14610 from enrico69/magento2:feature-enable-csv-processor-input-mode - Merged commits: 1. b9732d7 2. 68e0878 3. 9e01479
2 parents 07c2590 + 9e01479 commit bd82f26

File tree

1 file changed

+26
-6
lines changed
  • lib/internal/Magento/Framework/File

1 file changed

+26
-6
lines changed

lib/internal/Magento/Framework/File/Csv.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,37 @@ public function getDataPairs($file, $keyIndex = 0, $valueIndex = 1)
126126
/**
127127
* Saving data row array into file
128128
*
129-
* @param string $file
130-
* @param array $data
131-
* @return $this
129+
* @param string $file
130+
* @param array $data
131+
* @return $this
132+
* @throws \Magento\Framework\Exception\FileSystemException
133+
* @deprecated
134+
* @see appendData
132135
*/
133136
public function saveData($file, $data)
134137
{
135-
$fh = fopen($file, 'w');
138+
return $this->appendData($file, $data, 'w');
139+
}
140+
141+
/**
142+
* Replace the saveData method by allowing to select the input mode
143+
*
144+
* @param string $file
145+
* @param array $data
146+
* @param string $mode
147+
*
148+
* @return $this
149+
*
150+
* @throws \Magento\Framework\Exception\FileSystemException
151+
*/
152+
public function appendData($file, $data, $mode = 'w')
153+
{
154+
$fileHandler = fopen($file, $mode);
136155
foreach ($data as $dataRow) {
137-
$this->file->filePutCsv($fh, $dataRow, $this->_delimiter, $this->_enclosure);
156+
$this->file->filePutCsv($fileHandler, $dataRow, $this->_delimiter, $this->_enclosure);
138157
}
139-
fclose($fh);
158+
fclose($fileHandler);
159+
140160
return $this;
141161
}
142162
}

0 commit comments

Comments
 (0)