ILIAS  eassessment Revision 61809
 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 
32 if (!defined('DEBUGMODE_ENABLED')) {
33  define('DEBUGMODE_ENABLED', false);
34 }
35 
36 
46  const STORAGE_MEMORY = 1;
47  const STORAGE_DISK = 2;
48 
54  private $_tempFileName = '';
55 
62  public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') {
63  // Open temporary storage
64  if ($pTemporaryStorage == self::STORAGE_MEMORY) {
65  $this->openMemory();
66  } else {
67  // Create temporary filename
68  $this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
69 
70  // Open storage
71  if ($this->openUri($this->_tempFileName) === false) {
72  // Fallback to memory...
73  $this->openMemory();
74  }
75  }
76 
77  // Set default values
78  if (DEBUGMODE_ENABLED) {
79  $this->setIndent(true);
80  }
81  }
82 
86  public function __destruct() {
87  // Unlink temporary files
88  if ($this->_tempFileName != '') {
89  @unlink($this->_tempFileName);
90  }
91  }
92 
98  public function getData() {
99  if ($this->_tempFileName == '') {
100  return $this->outputMemory(true);
101  } else {
102  $this->flush();
103  return file_get_contents($this->_tempFileName);
104  }
105  }
106 
113  public function writeRawData($text)
114  {
115  if (method_exists($this, 'writeRaw')) {
116  return $this->writeRaw(htmlspecialchars($text));
117  }
118 
119  return $this->text($text);
120  }
121 }