From 75c8e7e8166d0946ca604984875d8866203af907 Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Wed, 2 Jul 2014 17:21:43 +0400 Subject: [PATCH] [NEW] Introduced CopyFileException. --- CHANGELOG.md | 2 +- src/PhpWord/Exception/CopyFileException.php | 39 +++++++++++++++++++ src/PhpWord/Template.php | 9 +++-- src/PhpWord/Writer/AbstractWriter.php | 7 +++- .../Tests/Exception/CopyFileExceptionTest.php | 39 +++++++++++++++++++ 5 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 src/PhpWord/Exception/CopyFileException.php create mode 100644 tests/PhpWord/Tests/Exception/CopyFileExceptionTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 53533148..f1ac091e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap - PclZip: Remove temporary file after used - @andrew-kzoo GH-265 - Autoloader: Add the ability to set the autoloader options - @bskrtich GH-267 - Element: Refactor elements to move set relation Id from container to element - @ivanlanin -- Introduced CreateTemporaryFileException - @RomanSyroeshko +- Introduced CreateTemporaryFileException, CopyFileException - @RomanSyroeshko ## 0.11.1 - 2 June 2014 diff --git a/src/PhpWord/Exception/CopyFileException.php b/src/PhpWord/Exception/CopyFileException.php new file mode 100644 index 00000000..97a900e3 --- /dev/null +++ b/src/PhpWord/Exception/CopyFileException.php @@ -0,0 +1,39 @@ +tempFileName)) { - throw new Exception("Could not copy the template from {$strFilename} to {$this->tempFileName}."); + if (false === copy($strFilename, $this->tempFileName)) { + throw new CopyFileException($strFilename, $this->tempFileName); } $this->zipClass = new ZipArchive(); diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 346e9b66..8e7cb71d 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -17,6 +17,7 @@ namespace PhpOffice\PhpWord\Writer; +use PhpOffice\PhpWord\Exception\CopyFileException; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\ZipArchive; @@ -233,14 +234,16 @@ abstract class AbstractWriter implements WriterInterface /** * Cleanup temporary file + * + * @throws \PhpOffice\PhpWord\Exception\CopyFileException */ protected function cleanupTempFile() { if ($this->originalFilename != $this->tempFilename) { // @codeCoverageIgnoreStart // Can't find any test case. Uncomment when found. - if (copy($this->tempFilename, $this->originalFilename) === false) { - throw new Exception("Could not copy temporary zip file."); + if (false === copy($this->tempFilename, $this->originalFilename)) { + throw new CopyFileException($this->tempFilename, $this->originalFilename); } // @codeCoverageIgnoreEnd @unlink($this->tempFilename); diff --git a/tests/PhpWord/Tests/Exception/CopyFileExceptionTest.php b/tests/PhpWord/Tests/Exception/CopyFileExceptionTest.php new file mode 100644 index 00000000..3d92595f --- /dev/null +++ b/tests/PhpWord/Tests/Exception/CopyFileExceptionTest.php @@ -0,0 +1,39 @@ +