1 | <?php |
||
36 | class XMLWriter extends \XMLWriter |
||
37 | { |
||
38 | /** Temporary storage method */ |
||
39 | const STORAGE_MEMORY = 1; |
||
40 | const STORAGE_DISK = 2; |
||
41 | |||
42 | /** |
||
43 | * Temporary filename |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | private $tempFileName = ''; |
||
48 | |||
49 | /** |
||
50 | * Create a new \PhpOffice\PhpPowerpoint\Shared\XMLWriter instance |
||
51 | * |
||
52 | * @param int $pTemporaryStorage Temporary storage location |
||
53 | * @param string $pTemporaryStorageDir Temporary storage folder |
||
54 | */ |
||
55 | 1 | public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = null, $compatibility = false) |
|
56 | { |
||
57 | // Open temporary storage |
||
58 | 1 | if ($pTemporaryStorage == self::STORAGE_MEMORY) { |
|
59 | 1 | $this->openMemory(); |
|
60 | 1 | } else { |
|
61 | 1 | if (!is_dir($pTemporaryStorageDir)) { |
|
62 | 1 | $pTemporaryStorageDir = sys_get_temp_dir(); |
|
63 | 1 | } |
|
64 | // Create temporary filename |
||
65 | 1 | $this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml'); |
|
66 | |||
67 | // Open storage |
||
68 | 1 | $this->openUri($this->tempFileName); |
|
69 | } |
||
70 | |||
71 | 1 | if ($compatibility) { |
|
72 | $this->setIndent(false); |
||
73 | $this->setIndentString(''); |
||
74 | } else { |
||
75 | 1 | $this->setIndent(true); |
|
76 | 1 | $this->setIndentString(' '); |
|
77 | } |
||
78 | 1 | } |
|
79 | |||
80 | /** |
||
81 | * Destructor |
||
82 | */ |
||
83 | 1 | public function __destruct() |
|
93 | |||
94 | /** |
||
95 | * Get written data |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 1 | public function getData() |
|
108 | |||
109 | |||
110 | /** |
||
111 | * Write simple element and attribute(s) block |
||
112 | * |
||
113 | * There are two options: |
||
114 | * 1. If the `$attributes` is an array, then it's an associative array of attributes |
||
115 | * 2. If not, then it's a simple attribute-value pair |
||
116 | * |
||
117 | * @param string $element |
||
118 | * @param string|array $attributes |
||
119 | * @param string $value |
||
120 | * @return void |
||
121 | */ |
||
122 | public function writeElementBlock($element, $attributes, $value = null) |
||
133 | |||
134 | /** |
||
135 | * Write element if ... |
||
136 | * |
||
137 | * @param bool $condition |
||
138 | * @param string $element |
||
139 | * @param string $attribute |
||
140 | * @param mixed $value |
||
141 | * @return void |
||
142 | */ |
||
143 | public function writeElementIf($condition, $element, $attribute = null, $value = null) |
||
155 | |||
156 | /** |
||
157 | * Write attribute if ... |
||
158 | * |
||
159 | * @param bool $condition |
||
160 | * @param string $attribute |
||
161 | * @param mixed $value |
||
162 | * @return void |
||
163 | */ |
||
164 | public function writeAttributeIf($condition, $attribute, $value) |
||
170 | } |
||
171 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.