Test scrutinizer
This commit is contained in:
parent
11499aad9a
commit
b60b1d25c0
|
@ -93,18 +93,18 @@ class Ods extends BaseWriter
|
||||||
// garbage collect
|
// garbage collect
|
||||||
$this->spreadSheet->garbageCollect();
|
$this->spreadSheet->garbageCollect();
|
||||||
|
|
||||||
// If $pFilename is php://output or php://stdout, make it a temporary file...
|
|
||||||
$originalFilename = $pFilename;
|
$originalFilename = $pFilename;
|
||||||
if (is_resource($pFilename)) {
|
if (is_resource($pFilename)) {
|
||||||
$this->fileHandle = $pFilename;
|
$this->fileHandle = $pFilename;
|
||||||
} elseif (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
|
|
||||||
// If $pFilename is php://output or php://stdout, make it a temporary file...
|
|
||||||
$pFilename = @tempnam(File::sysGetTempDir(), 'phpxltmp');
|
|
||||||
if ($pFilename == '') {
|
|
||||||
$pFilename = $originalFilename;
|
|
||||||
}
|
|
||||||
$this->fileHandle = fopen($pFilename, 'wb+');
|
|
||||||
} else {
|
} else {
|
||||||
|
// If $pFilename is php://output or php://stdout, make it a temporary file...
|
||||||
|
if (in_array(strtolower($pFilename), ['php://output', 'php://stdout'], true)) {
|
||||||
|
$pFilename = @tempnam(File::sysGetTempDir(), 'phpxltmp');
|
||||||
|
if ($pFilename === '') {
|
||||||
|
$pFilename = $originalFilename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->fileHandle = fopen($pFilename, 'wb+');
|
$this->fileHandle = fopen($pFilename, 'wb+');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,11 +128,19 @@ class Ods extends BaseWriter
|
||||||
rewind($this->fileHandle);
|
rewind($this->fileHandle);
|
||||||
|
|
||||||
// If a temporary file was used, copy it to the correct file stream
|
// If a temporary file was used, copy it to the correct file stream
|
||||||
if ($originalFilename != $pFilename) {
|
if ($originalFilename !== $pFilename) {
|
||||||
if (stream_copy_to_stream($this->fileHandle, fopen($originalFilename, 'wb+')) === false) {
|
$destinationFileHandle = fopen($originalFilename, 'wb+');
|
||||||
|
if (!is_resource($destinationFileHandle)) {
|
||||||
|
throw new WriterException("Could not open resource $originalFilename for writing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stream_copy_to_stream($this->fileHandle, $destinationFileHandle) === false) {
|
||||||
throw new WriterException("Could not copy temporary zip file $pFilename to $originalFilename.");
|
throw new WriterException("Could not copy temporary zip file $pFilename to $originalFilename.");
|
||||||
}
|
}
|
||||||
@unlink($pFilename);
|
|
||||||
|
if (is_string($pFilename) && !unlink($pFilename)) {
|
||||||
|
throw new WriterException('Could not unlink temporary zip file.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +154,7 @@ class Ods extends BaseWriter
|
||||||
private function createZip()
|
private function createZip()
|
||||||
{
|
{
|
||||||
// Try opening the ZIP file
|
// Try opening the ZIP file
|
||||||
if ($this->fileHandle === false) {
|
if (!is_resource($this->fileHandle)) {
|
||||||
throw new WriterException('Could not open resource for writing.');
|
throw new WriterException('Could not open resource for writing.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,22 +185,21 @@ class Xlsx extends BaseWriter
|
||||||
$this->spreadSheet->garbageCollect();
|
$this->spreadSheet->garbageCollect();
|
||||||
|
|
||||||
$originalFilename = $pFilename;
|
$originalFilename = $pFilename;
|
||||||
|
|
||||||
if (is_resource($pFilename)) {
|
if (is_resource($pFilename)) {
|
||||||
$this->fileHandle = $pFilename;
|
$this->fileHandle = $pFilename;
|
||||||
} elseif (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
|
|
||||||
// If $pFilename is php://output or php://stdout, make it a temporary file...
|
|
||||||
$pFilename = @tempnam(File::sysGetTempDir(), 'phpxltmp');
|
|
||||||
if ($pFilename == '') {
|
|
||||||
$pFilename = $originalFilename;
|
|
||||||
}
|
|
||||||
$this->fileHandle = fopen($pFilename, 'wb+');
|
|
||||||
} else {
|
} else {
|
||||||
|
// If $pFilename is php://output or php://stdout, make it a temporary file...
|
||||||
|
if (in_array(strtolower($pFilename), ['php://output', 'php://stdout'], true)) {
|
||||||
|
$pFilename = @tempnam(File::sysGetTempDir(), 'phpxltmp');
|
||||||
|
if ($pFilename === '') {
|
||||||
|
$pFilename = $originalFilename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->fileHandle = fopen($pFilename, 'wb+');
|
$this->fileHandle = fopen($pFilename, 'wb+');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try opening the ZIP file
|
if (!is_resource($this->fileHandle)) {
|
||||||
if ($this->fileHandle === false) {
|
|
||||||
throw new WriterException('Could not open resource for writing.');
|
throw new WriterException('Could not open resource for writing.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,11 +427,19 @@ class Xlsx extends BaseWriter
|
||||||
rewind($this->fileHandle);
|
rewind($this->fileHandle);
|
||||||
|
|
||||||
// If a temporary file was used, copy it to the correct file stream
|
// If a temporary file was used, copy it to the correct file stream
|
||||||
if ($originalFilename != $pFilename) {
|
if ($originalFilename !== $pFilename) {
|
||||||
if (stream_copy_to_stream($this->fileHandle, fopen($originalFilename, 'wb+')) === false) {
|
$destinationFileHandle = fopen($originalFilename, 'wb+');
|
||||||
|
if (!is_resource($destinationFileHandle)) {
|
||||||
|
throw new WriterException("Could not open resource $originalFilename for writing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stream_copy_to_stream($this->fileHandle, $destinationFileHandle) === false) {
|
||||||
throw new WriterException("Could not copy temporary zip file $pFilename to $originalFilename.");
|
throw new WriterException("Could not copy temporary zip file $pFilename to $originalFilename.");
|
||||||
}
|
}
|
||||||
@unlink($pFilename);
|
|
||||||
|
if (is_string($pFilename) && !unlink($pFilename)) {
|
||||||
|
throw new WriterException('Could not unlink temporary zip file.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new WriterException('PhpSpreadsheet object unassigned.');
|
throw new WriterException('PhpSpreadsheet object unassigned.');
|
||||||
|
|
Loading…
Reference in New Issue