Added PHPWord_Exception and exception when could not copy the template

This commit is contained in:
Progi1984 2013-12-15 13:18:07 +01:00
parent 5d6bb15825
commit 1b849ec1bb
3 changed files with 59 additions and 3 deletions

View File

@ -29,4 +29,5 @@ Fixed in branch for release 0.7 :
- General: (MarkBaker) - Add superscript/subscript styling in Excel2007 Writer
- General: (deds) - add indentation support to paragraphs
- General: (Progi1984) GH-27 - Support for Composer
- General: (Progi1984) - Basic CI with Travis
- General: (Progi1984) - Basic CI with Travis
- General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template

52
src/PHPWord/Exception.php Normal file
View File

@ -0,0 +1,52 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2009 - 2010 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2009 - 2010 PHPWord (http://www.codeplex.com/PHPWord)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPWord_Exception
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2006 - 2013 PHPWord (http://www.codeplex.com/PHPWord)
*/
class PHPWord_Exception extends Exception {
/**
* Error handler callback
*
* @param mixed $code
* @param mixed $string
* @param mixed $file
* @param mixed $line
* @param mixed $context
*/
public static function errorHandlerCallback($code, $string, $file, $line, $context) {
$e = new self($string, $code);
$e->line = $line;
$e->file = $file;
throw $e;
}
}

View File

@ -65,8 +65,11 @@ class PHPWord_Template {
public function __construct($strFilename) {
$path = dirname($strFilename);
$this->_tempFileName = $path.DIRECTORY_SEPARATOR.time().'.docx';
copy($strFilename, $this->_tempFileName); // Copy the source File to the temp File
// Copy the source File to the temp File
if(!copy($strFilename, $this->_tempFileName)){
throw new PHPWord_Exception('Could not copy the template from '.$strFilename.' to '.$this->_tempFileName.'.');
}
$this->_objZip = new ZipArchive();
$this->_objZip->open($this->_tempFileName);