[NEW] Introduced CreateTemporaryFileException.
This commit is contained in:
parent
d8aef5c502
commit
3c694ea572
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
final class CreateTemporaryFileException extends Exception
|
||||||
|
{
|
||||||
|
protected $message = 'Could not create a temporary file with unique name in the specified directory.';
|
||||||
|
|
||||||
|
final public function __construct() {
|
||||||
|
parent::__construct($this->message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord;
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\Shared\String;
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
use PhpOffice\PhpWord\Shared\ZipArchive;
|
use PhpOffice\PhpWord\Shared\ZipArchive;
|
||||||
|
|
@ -54,24 +55,20 @@ class Template
|
||||||
*/
|
*/
|
||||||
private $headerXMLs = array();
|
private $headerXMLs = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Document footer XML
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private $footerXMLs = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Template Object
|
* Create a new Template Object
|
||||||
*
|
*
|
||||||
|
* @since 0.12.0 Throws CreateTemporaryFileException instead of Exception.
|
||||||
|
*
|
||||||
* @param string $strFilename
|
* @param string $strFilename
|
||||||
|
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
|
||||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||||
*/
|
*/
|
||||||
public function __construct($strFilename)
|
public function __construct($strFilename)
|
||||||
{
|
{
|
||||||
$this->tempFileName = tempnam(sys_get_temp_dir(), '');
|
$this->tempFileName = tempnam(sys_get_temp_dir(), '');
|
||||||
if ($this->tempFileName === false) {
|
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
|
// Copy the source File to the temp File
|
||||||
|
|
@ -98,6 +95,13 @@ class Template
|
||||||
$this->documentXML = $this->zipClass->getFromName('word/document.xml');
|
$this->documentXML = $this->zipClass->getFromName('word/document.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Document footer XML
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
private $footerXMLs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies XSL style sheet to template's parts
|
* Applies XSL style sheet to template's parts
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Exception;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
|
||||||
|
*/
|
||||||
|
class CreateTemporaryFileExceptionTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* CreateTemporaryFileException can be thrown.
|
||||||
|
*
|
||||||
|
* @covers ::__construct()
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function testCreateTemporaryFileExceptionCanBeThrown()
|
||||||
|
{
|
||||||
|
throw new CreateTemporaryFileException();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue