ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
XMLWriter.php
Go to the documentation of this file.
1<?php
2
4
5class XMLWriter extends \XMLWriter
6{
7 public static $debugEnabled = false;
8
10 const STORAGE_MEMORY = 1;
11 const STORAGE_DISK = 2;
12
18 private $tempFileName = '';
19
26 public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = null)
27 {
28 // Open temporary storage
29 if ($pTemporaryStorage == self::STORAGE_MEMORY) {
30 $this->openMemory();
31 } else {
32 // Create temporary filename
33 if ($pTemporaryStorageFolder === null) {
34 $pTemporaryStorageFolder = File::sysGetTempDir();
35 }
36 $this->tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
37
38 // Open storage
39 if ($this->openUri($this->tempFileName) === false) {
40 // Fallback to memory...
41 $this->openMemory();
42 }
43 }
44
45 // Set default values
46 if (self::$debugEnabled) {
47 $this->setIndent(true);
48 }
49 }
50
54 public function __destruct()
55 {
56 // Unlink temporary files
57 if ($this->tempFileName != '') {
58 @unlink($this->tempFileName);
59 }
60 }
61
67 public function getData()
68 {
69 if ($this->tempFileName == '') {
70 return $this->outputMemory(true);
71 }
72 $this->flush();
73
74 return file_get_contents($this->tempFileName);
75 }
76
84 public function writeRawData($text)
85 {
86 if (is_array($text)) {
87 $text = implode("\n", $text);
88 }
89
90 return $this->writeRaw(htmlspecialchars($text ?? ''));
91 }
92}
An exception for terminatinating execution or to throw for unit testing.
static sysGetTempDir()
Get the systems temporary directory.
Definition: File.php:111
const STORAGE_MEMORY
Temporary storage method.
Definition: XMLWriter.php:10
writeRawData($text)
Wrapper method for writeRaw.
Definition: XMLWriter.php:84
__construct($pTemporaryStorage=self::STORAGE_MEMORY, $pTemporaryStorageFolder=null)
Create a new XMLWriter instance.
Definition: XMLWriter.php:26
$text
Definition: errorreport.php:18