Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Check file handle is valid before manipulating it
Browse files Browse the repository at this point in the history
This fixes issues when something went wrong on reader/writer init and the developer wants to close the reader/writer.
The file handle may not be defined so we need to add a check for it, before actually using it.
  • Loading branch information
Adrien Loison committed Apr 12, 2016
1 parent 71a6f6a commit 8bb42eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Spout/Writer/ODS/Internal/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ protected function getCellContent($cellValue, $styleIndex, $numTimesValueRepeate
*/
public function close()
{
if (!is_resource($this->sheetFilePointer)) {
return;
}

fclose($this->sheetFilePointer);
}
}
4 changes: 4 additions & 0 deletions src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public function writeString($string)
*/
public function close()
{
if (!is_resource($this->sharedStringsFilePointer)) {
return;
}

fwrite($this->sharedStringsFilePointer, '</sst>');

// Replace the default strings count with the actual number of shared strings in the file header
Expand Down
4 changes: 4 additions & 0 deletions src/Spout/Writer/XLSX/Internal/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public function addRow($dataRow, $style)
*/
public function close()
{
if (!is_resource($this->sheetFilePointer)) {
return;
}

fwrite($this->sheetFilePointer, '</sheetData>');
fwrite($this->sheetFilePointer, '</worksheet>');
fclose($this->sheetFilePointer);
Expand Down

0 comments on commit 8bb42eb

Please sign in to comment.