From 3cd60f76de701f05459e9fe2836e92dd78179764 Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Fri, 17 Jan 2014 00:02:09 -0800 Subject: [PATCH] https://github.com/PHPOffice/PHPWord/issues/56 Postprocessing of documents returned by Template class before moving to final destination --- Classes/PHPWord/Template.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Classes/PHPWord/Template.php b/Classes/PHPWord/Template.php index a01a854166..2cf198ec79 100755 --- a/Classes/PHPWord/Template.php +++ b/Classes/PHPWord/Template.php @@ -117,14 +117,9 @@ public function getVariables() /** * Save Template * - * @param string $strFilename + * @return string */ - public function save($strFilename) - { - if (file_exists($strFilename)) { - unlink($strFilename); - } - + public function save() { $this->_objZip->addFromString('word/document.xml', $this->_documentXML); // Close zip file @@ -132,6 +127,21 @@ public function save($strFilename) throw new Exception('Could not close zip file.'); } - rename($this->_tempFileName, $strFilename); + return $this->_tempFileName; + } + + /** + * Save Template As... + * + * @param string $strFilename + */ + public function saveAs($strFilename) { + $tempFilename = $this->save(); + + if (file_exists($strFilename)) { + unlink($strFilename); + } + + rename($tempFilename, $strFilename); } -} \ No newline at end of file +}