ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
XMLWriter.php
Go to the documentation of this file.
1 <?php
28 if (!defined('DATE_W3C')) {
29  define('DATE_W3C', 'Y-m-d\TH:i:sP');
30 }
31 
41  const STORAGE_MEMORY = 1;
42  const STORAGE_DISK = 2;
43 
49  private $_xmlWriter;
50 
56  private $_tempFileName = '';
57 
64  public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') {
65  // Create internal XMLWriter
66  $this->_xmlWriter = new XMLWriter();
67 
68  // Open temporary storage
69  if ($pTemporaryStorage == self::STORAGE_MEMORY) {
70  $this->_xmlWriter->openMemory();
71  } else {
72  // Create temporary filename
73  $this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
74 
75  // Open storage
76  if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
77  // Fallback to memory...
78  $this->_xmlWriter->openMemory();
79  }
80  }
81 
82  // Set default values
83  $this->_xmlWriter->setIndent(true);
84  }
85 
89  public function __destruct() {
90  // Desctruct XMLWriter
91  unset($this->_xmlWriter);
92 
93  // Unlink temporary files
94  if ($this->_tempFileName != '') {
95  @unlink($this->_tempFileName);
96  }
97  }
98 
104  public function getData() {
105  if ($this->_tempFileName == '') {
106  return $this->_xmlWriter->outputMemory(true);
107  } else {
108  $this->_xmlWriter->flush();
109  return file_get_contents($this->_tempFileName);
110  }
111  }
112 
119  public function __call($function, $args) {
120  try {
121  @call_user_func_array(array($this->_xmlWriter, $function), $args);
122  } catch (Exception $ex) {
123  // Do nothing!
124  }
125  }
126 
133  public function writeRaw($text)
134  {
135  if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
136  return $this->_xmlWriter->writeRaw(htmlspecialchars($text));
137  }
138 
139  return $this->text($text);
140  }
141 }