From 3c694ea572304c0680b3ce4c5da193f433554a1d Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Wed, 2 Jul 2014 12:42:50 +0400 Subject: [PATCH] [NEW] Introduced CreateTemporaryFileException. --- .../CreateTemporaryFileException.php | 30 ++++++++++++++ src/PhpWord/Template.php | 20 ++++++---- .../CreateTemporaryFileExceptionTest.php | 39 +++++++++++++++++++ 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 src/PhpWord/Exception/CreateTemporaryFileException.php create mode 100644 tests/PhpWord/Tests/Exception/CreateTemporaryFileExceptionTest.php diff --git a/src/PhpWord/Exception/CreateTemporaryFileException.php b/src/PhpWord/Exception/CreateTemporaryFileException.php new file mode 100644 index 00000000..f635dd6b --- /dev/null +++ b/src/PhpWord/Exception/CreateTemporaryFileException.php @@ -0,0 +1,30 @@ +message); + } +} diff --git a/src/PhpWord/Template.php b/src/PhpWord/Template.php index 21e8b988..6cfa664f 100644 --- a/src/PhpWord/Template.php +++ b/src/PhpWord/Template.php @@ -17,6 +17,7 @@ namespace PhpOffice\PhpWord; +use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Shared\String; use PhpOffice\PhpWord\Shared\ZipArchive; @@ -54,24 +55,20 @@ class Template */ private $headerXMLs = array(); - /** - * Document footer XML - * - * @var string[] - */ - private $footerXMLs = array(); - /** * Create a new Template Object * + * @since 0.12.0 Throws CreateTemporaryFileException instead of Exception. + * * @param string $strFilename + * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException * @throws \PhpOffice\PhpWord\Exception\Exception */ public function __construct($strFilename) { $this->tempFileName = tempnam(sys_get_temp_dir(), ''); if ($this->tempFileName === false) { - throw new Exception('Could not create temporary file with unique name in the default temporary directory.'); + throw new CreateTemporaryFileException(); } // Copy the source File to the temp File @@ -98,6 +95,13 @@ class Template $this->documentXML = $this->zipClass->getFromName('word/document.xml'); } + /** + * Document footer XML + * + * @var string[] + */ + private $footerXMLs = array(); + /** * Applies XSL style sheet to template's parts * diff --git a/tests/PhpWord/Tests/Exception/CreateTemporaryFileExceptionTest.php b/tests/PhpWord/Tests/Exception/CreateTemporaryFileExceptionTest.php new file mode 100644 index 00000000..7cf0cb77 --- /dev/null +++ b/tests/PhpWord/Tests/Exception/CreateTemporaryFileExceptionTest.php @@ -0,0 +1,39 @@ +