ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Writer.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\Xml;
4
5use XMLWriter;
6
31class Writer extends XMLWriter {
32
34
44 protected $adhocNamespaces = [];
45
54 protected $namespacesWritten = false;
55
98 function write($value) {
99
100 Serializer\standardSerializer($this, $value);
101
102 }
103
121 function startElement($name) {
122
123 if ($name[0] === '{') {
124
125 list($namespace, $localName) =
127
128 if (array_key_exists($namespace, $this->namespaceMap)) {
129 $result = $this->startElementNS(
130 $this->namespaceMap[$namespace] === '' ? null : $this->namespaceMap[$namespace],
131 $localName,
132 null
133 );
134 } else {
135
136 // An empty namespace means it's the global namespace. This is
137 // allowed, but it mustn't get a prefix.
138 if ($namespace === "" || $namespace === null) {
139 $result = $this->startElement($localName);
140 $this->writeAttribute('xmlns', '');
141 } else {
142 if (!isset($this->adhocNamespaces[$namespace])) {
143 $this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces) + 1);
144 }
145 $result = $this->startElementNS($this->adhocNamespaces[$namespace], $localName, $namespace);
146 }
147 }
148
149 } else {
150 $result = parent::startElement($name);
151 }
152
153 if (!$this->namespacesWritten) {
154
155 foreach ($this->namespaceMap as $namespace => $prefix) {
156 $this->writeAttribute(($prefix ? 'xmlns:' . $prefix : 'xmlns'), $namespace);
157 }
158 $this->namespacesWritten = true;
159
160 }
161
162 return $result;
163
164 }
165
189 function writeElement($name, $content = null) {
190
191 $this->startElement($name);
192 if (!is_null($content)) {
193 $this->write($content);
194 }
195 $this->endElement();
196
197 }
198
211 function writeAttributes(array $attributes) {
212
213 foreach ($attributes as $name => $value) {
214 $this->writeAttribute($name, $value);
215 }
216
217 }
218
230 function writeAttribute($name, $value) {
231
232 if ($name[0] === '{') {
233
234 list(
236 $localName
238
239 if (array_key_exists($namespace, $this->namespaceMap)) {
240 // It's an attribute with a namespace we know
241 $this->writeAttribute(
242 $this->namespaceMap[$namespace] . ':' . $localName,
243 $value
244 );
245 } else {
246
247 // We don't know the namespace, we must add it in-line
248 if (!isset($this->adhocNamespaces[$namespace])) {
249 $this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces) + 1);
250 }
251 $this->writeAttributeNS(
252 $this->adhocNamespaces[$namespace],
253 $localName,
255 $value
256 );
257
258 }
259
260 } else {
261 return parent::writeAttribute($name, $value);
262 }
263
264 }
265
266}
$result
An exception for terminatinating execution or to throw for unit testing.
static parseClarkNotation($str)
Parses a clark-notation string, and returns the namespace and element name components.
Definition: Service.php:274
The XML Writer class.
Definition: Writer.php:31
writeAttribute($name, $value)
Writes a new attribute.
Definition: Writer.php:230
writeElement($name, $content=null)
Write a full element tag and it's contents.
Definition: Writer.php:189
startElement($name)
Opens a new element.
Definition: Writer.php:121
write($value)
Writes a value to the output stream.
Definition: Writer.php:98
writeAttributes(array $attributes)
Writes a list of attributes.
Definition: Writer.php:211
if($err=$client->getError()) $namespace
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
standardSerializer(Writer $writer, $value)
This function is the 'default' serializer that is able to serialize most things, and delegates to oth...
Definition: functions.php:164
trait ContextStackTrait
Context Stack.