Check file handle is valid before manipulating it

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.
This commit is contained in:
Adrien Loison 2016-04-12 10:25:08 -07:00
parent 71a6f6a937
commit 8bb42ebc23
3 changed files with 12 additions and 0 deletions

View File

@ -218,6 +218,10 @@ class Worksheet implements WorksheetInterface
*/ */
public function close() public function close()
{ {
if (!is_resource($this->sheetFilePointer)) {
return;
}
fclose($this->sheetFilePointer); fclose($this->sheetFilePointer);
} }
} }

View File

@ -88,6 +88,10 @@ EOD;
*/ */
public function close() public function close()
{ {
if (!is_resource($this->sharedStringsFilePointer)) {
return;
}
fwrite($this->sharedStringsFilePointer, '</sst>'); fwrite($this->sharedStringsFilePointer, '</sst>');
// Replace the default strings count with the actual number of shared strings in the file header // Replace the default strings count with the actual number of shared strings in the file header

View File

@ -178,6 +178,10 @@ EOD;
*/ */
public function close() public function close()
{ {
if (!is_resource($this->sheetFilePointer)) {
return;
}
fwrite($this->sheetFilePointer, '</sheetData>'); fwrite($this->sheetFilePointer, '</sheetData>');
fwrite($this->sheetFilePointer, '</worksheet>'); fwrite($this->sheetFilePointer, '</worksheet>');
fclose($this->sheetFilePointer); fclose($this->sheetFilePointer);