Refactored usages of "tempnam()" function.
This commit is contained in:
parent
56c3d8eda2
commit
e6d88a27e8
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
||||
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
|
|
@ -423,13 +424,18 @@ class Image extends AbstractElement
|
|||
*
|
||||
* @param string $source
|
||||
* @return array|null
|
||||
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
|
||||
*/
|
||||
private function getArchiveImageSize($source)
|
||||
{
|
||||
$imageData = null;
|
||||
$source = substr($source, 6);
|
||||
list($zipFilename, $imageFilename) = explode('#', $source);
|
||||
|
||||
$tempFilename = tempnam(Settings::getTempDir(), 'PHPWordImage');
|
||||
if (false === $tempFilename) {
|
||||
throw new CreateTemporaryFileException();
|
||||
}
|
||||
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($zipFilename) !== false) {
|
||||
|
|
@ -437,7 +443,7 @@ class Image extends AbstractElement
|
|||
$imageContent = $zip->getFromName($imageFilename);
|
||||
if ($imageContent !== false) {
|
||||
file_put_contents($tempFilename, $imageContent);
|
||||
$imageData = @getimagesize($tempFilename);
|
||||
$imageData = getimagesize($tempFilename);
|
||||
unlink($tempFilename);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,12 +66,12 @@ class XMLWriter
|
|||
$this->xmlWriter->openMemory();
|
||||
} else {
|
||||
// Create temporary filename
|
||||
$this->tempFile = @tempnam($tempFolder, 'xml');
|
||||
$this->tempFile = tempnam($tempFolder, 'xml');
|
||||
|
||||
// Fallback to memory when temporary file cannot be used
|
||||
// @codeCoverageIgnoreStart
|
||||
// Can't find any test case. Uncomment when found.
|
||||
if ($this->xmlWriter->openUri($this->tempFile) === false) {
|
||||
if (false === $this->tempFile || false === $this->xmlWriter->openUri($this->tempFile)) {
|
||||
$this->xmlWriter->openMemory();
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
|||
|
|
@ -220,13 +220,10 @@ abstract class AbstractWriter implements WriterInterface
|
|||
// Temporary file
|
||||
$this->originalFilename = $filename;
|
||||
if (strtolower($filename) == 'php://output' || strtolower($filename) == 'php://stdout') {
|
||||
$filename = tempnam(Settings::getTempDir(), 'phpword_');
|
||||
// @codeCoverageIgnoreStart
|
||||
// Can't find any test case. Uncomment when found.
|
||||
if ($filename == '') {
|
||||
$filename = tempnam(Settings::getTempDir(), 'PhpWord');
|
||||
if (false === $filename) {
|
||||
$filename = $this->originalFilename;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
$this->tempFilename = $filename;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Tests;
|
||||
|
||||
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||
use PhpOffice\PhpWord\IOFactory;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
|
|
@ -39,10 +40,15 @@ class TestHelperDOCX
|
|||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param string $writerName
|
||||
* @return \PhpOffice\PhpWord\Tests\XmlDocument
|
||||
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
|
||||
*/
|
||||
public static function getDocument(PhpWord $phpWord, $writerName = 'Word2007')
|
||||
{
|
||||
self::$file = tempnam(Settings::getTempDir(), 'PhpWord');
|
||||
if (false === self::$file) {
|
||||
throw new CreateTemporaryFileException();
|
||||
}
|
||||
|
||||
if (!is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) {
|
||||
mkdir(Settings::getTempDir() . '/PhpWord_Unit_Test/');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue