Skip to content

Commit 3c694ea

Browse files
author
Roman Syroeshko
committed
[NEW] Introduced CreateTemporaryFileException.
1 parent d8aef5c commit 3c694ea

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2014 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\Exception;
19+
20+
/**
21+
* @since 0.12.0
22+
*/
23+
final class CreateTemporaryFileException extends Exception
24+
{
25+
protected $message = 'Could not create a temporary file with unique name in the specified directory.';
26+
27+
final public function __construct() {
28+
parent::__construct($this->message);
29+
}
30+
}

src/PhpWord/Template.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpWord;
1919

20+
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
2021
use PhpOffice\PhpWord\Exception\Exception;
2122
use PhpOffice\PhpWord\Shared\String;
2223
use PhpOffice\PhpWord\Shared\ZipArchive;
@@ -54,24 +55,20 @@ class Template
5455
*/
5556
private $headerXMLs = array();
5657

57-
/**
58-
* Document footer XML
59-
*
60-
* @var string[]
61-
*/
62-
private $footerXMLs = array();
63-
6458
/**
6559
* Create a new Template Object
6660
*
61+
* @since 0.12.0 Throws CreateTemporaryFileException instead of Exception.
62+
*
6763
* @param string $strFilename
64+
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
6865
* @throws \PhpOffice\PhpWord\Exception\Exception
6966
*/
7067
public function __construct($strFilename)
7168
{
7269
$this->tempFileName = tempnam(sys_get_temp_dir(), '');
7370
if ($this->tempFileName === false) {
74-
throw new Exception('Could not create temporary file with unique name in the default temporary directory.');
71+
throw new CreateTemporaryFileException();
7572
}
7673

7774
// Copy the source File to the temp File
@@ -98,6 +95,13 @@ public function __construct($strFilename)
9895
$this->documentXML = $this->zipClass->getFromName('word/document.xml');
9996
}
10097

98+
/**
99+
* Document footer XML
100+
*
101+
* @var string[]
102+
*/
103+
private $footerXMLs = array();
104+
101105
/**
102106
* Applies XSL style sheet to template's parts
103107
*
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2014 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\Tests\Exception;
19+
20+
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
21+
22+
/**
23+
* @covers \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
24+
* @coversDefaultClass \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
25+
*/
26+
class CreateTemporaryFileExceptionTest extends \PHPUnit_Framework_TestCase
27+
{
28+
/**
29+
* CreateTemporaryFileException can be thrown.
30+
*
31+
* @covers ::__construct()
32+
* @expectedException \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
33+
* @test
34+
*/
35+
public function testCreateTemporaryFileExceptionCanBeThrown()
36+
{
37+
throw new CreateTemporaryFileException();
38+
}
39+
}

0 commit comments

Comments
 (0)