Skip to content

Commit 68e0878

Browse files
committed
Added a new method to replace the saveData one
1 parent b9732d7 commit 68e0878

File tree

1 file changed

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

1 file changed

+28
-6
lines changed

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,43 @@ 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
129+
* @param string $file
130+
* @param array $data
131+
* @return $this
132+
* @throws \Magento\Framework\Exception\FileSystemException
133+
* @deprecated
134+
* @see appendData
135+
*/
136+
public function saveData($file, $data)
137+
{
138+
$fh = fopen($file, 'w');
139+
foreach ($data as $dataRow) {
140+
$this->file->filePutCsv($fh, $dataRow, $this->_delimiter, $this->_enclosure);
141+
}
142+
fclose($fh);
143+
return $this;
144+
}
145+
146+
/**
147+
* Replace the saveData method by
148+
* allowing to select the input mode
149+
*
150+
* @param $file
151+
* @param $data
131152
* @param string $mode
132153
*
133154
* @return $this
134155
*
135156
* @throws \Magento\Framework\Exception\FileSystemException
136157
*/
137-
public function saveData($file, $data, $mode = 'w')
158+
public function appendData($file, $data, $mode = 'w')
138159
{
139-
$fh = fopen($file, $mode);
160+
$fileHandler = fopen($file, $mode);
140161
foreach ($data as $dataRow) {
141-
$this->file->filePutCsv($fh, $dataRow, $this->_delimiter, $this->_enclosure);
162+
$this->file->filePutCsv($fileHandler, $dataRow, $this->_delimiter, $this->_enclosure);
142163
}
143-
fclose($fh);
164+
fclose($fileHandler);
165+
144166
return $this;
145167
}
146168
}

0 commit comments

Comments
 (0)