5
* Copyright (c) 2006 - 2009 PHPExcel
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
* @package PHPExcel_Shared
23
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
24
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
* @version 1.7.0, 2009-08-10
28
if (!defined('DATE_W3C')) {
29
define('DATE_W3C', 'Y-m-d\TH:i:sP');
33
* PHPExcel_Shared_XMLWriter
36
* @package PHPExcel_Shared
37
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
39
class PHPExcel_Shared_XMLWriter {
40
/** Temporary storage method */
41
const STORAGE_MEMORY = 1;
42
const STORAGE_DISK = 2;
56
private $_tempFileName = '';
59
* Create a new PHPExcel_Shared_XMLWriter instance
61
* @param int $pTemporaryStorage Temporary storage location
62
* @param string $pTemporaryStorageFolder Temporary storage folder
64
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') {
65
// Create internal XMLWriter
66
$this->_xmlWriter = new XMLWriter();
68
// Open temporary storage
69
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
70
$this->_xmlWriter->openMemory();
72
// Create temporary filename
73
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
76
if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
77
// Fallback to memory...
78
$this->_xmlWriter->openMemory();
83
$this->_xmlWriter->setIndent(true);
89
public function __destruct() {
90
// Desctruct XMLWriter
91
unset($this->_xmlWriter);
93
// Unlink temporary files
94
if ($this->_tempFileName != '') {
95
@unlink($this->_tempFileName);
104
public function getData() {
105
if ($this->_tempFileName == '') {
106
return $this->_xmlWriter->outputMemory(true);
108
$this->_xmlWriter->flush();
109
return file_get_contents($this->_tempFileName);
114
* Catch function calls (and pass them to internal XMLWriter)
116
* @param unknown_type $function
117
* @param unknown_type $args
119
public function __call($function, $args) {
121
@call_user_func_array(array($this->_xmlWriter, $function), $args);
122
} catch (Exception $ex) {
128
* Fallback method for writeRaw, introduced in PHP 5.2
130
* @param string $text
133
public function writeRaw($text)
135
if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
136
return $this->_xmlWriter->writeRaw(htmlspecialchars($text));
139
return $this->text($text);