Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Output/Generator/Xml.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Common\Output\Generator;
8
9 use eZ\Publish\Core\REST\Common\Output\Generator;
10
14 class Xml extends Generator
15 {
21 protected $xmlWriter;
22
28 protected $hashGenerator;
29
35 protected $isEmpty = true;
36
42 protected $vendor;
43
48 public function __construct(Xml\FieldTypeHashGenerator $hashGenerator, $vendor = 'vnd.ez.api')
49 {
50 $this->hashGenerator = $hashGenerator;
51 $this->vendor = $vendor;
52 }
53
59 public function startDocument($data)
60 {
61 $this->checkStartDocument($data);
62
63 $this->isEmpty = true;
64
65 $this->xmlWriter = new \XMLWriter();
66 $this->xmlWriter->openMemory();
67 $this->xmlWriter->setIndent($this->formatOutput);
68 $this->xmlWriter->startDocument('1.0', 'UTF-8');
69 }
70
76 public function isEmpty()
77 {
78 return $this->isEmpty;
79 }
80
90 public function endDocument($data)
91 {
92 $this->checkEndDocument($data);
93
94 $this->xmlWriter->endDocument();
95
96 return $this->xmlWriter->outputMemory();
97 }
98
105 public function startObjectElement($name, $mediaTypeName = null)
106 {
107 $this->checkStartObjectElement($name);
108
109 $this->isEmpty = false;
110
111 $mediaTypeName = $mediaTypeName ?: $name;
112
113 $this->xmlWriter->startElement($name);
114
115 $this->startAttribute('media-type', $this->getMediaType($mediaTypeName));
116 $this->endAttribute('media-type');
117 }
118
124 public function endObjectElement($name)
125 {
126 $this->checkEndObjectElement($name);
127
128 $this->xmlWriter->endElement();
129 }
130
136 public function startHashElement($name)
137 {
138 $this->checkStartHashElement($name);
139
140 $this->isEmpty = false;
141
142 $this->xmlWriter->startElement($name);
143 }
144
150 public function endHashElement($name)
151 {
152 $this->checkEndHashElement($name);
153
154 $this->xmlWriter->endElement();
155 }
156
164 public function startValueElement($name, $value, $attributes = [])
165 {
166 $this->checkStartValueElement($name);
167
168 $this->xmlWriter->startElement($name);
169
170 foreach ($attributes as $attributeName => $attributeValue) {
171 $this->xmlWriter->startAttribute($attributeName);
172 $this->xmlWriter->text($attributeValue);
173 $this->xmlWriter->endAttribute();
174 }
175
176 $this->xmlWriter->text($value);
177 }
178
184 public function endValueElement($name)
185 {
186 $this->checkEndValueElement($name);
187
188 $this->xmlWriter->endElement();
189 }
190
196 public function startList($name)
197 {
198 $this->checkStartList($name);
199 }
200
206 public function endList($name)
207 {
208 $this->checkEndList($name);
209 }
210
217 public function startAttribute($name, $value)
218 {
219 $this->checkStartAttribute($name);
220
221 $this->xmlWriter->startAttribute($name);
222 $this->xmlWriter->text($value);
223 }
224
230 public function endAttribute($name)
231 {
232 $this->checkEndAttribute($name);
233
234 $this->xmlWriter->endAttribute();
235 }
236
244 public function getMediaType($name)
245 {
246 return $this->generateMediaTypeWithVendor($name, 'xml', $this->vendor);
247 }
248
257 public function generateFieldTypeHash($hashElementName, $hashValue)
258 {
259 $this->hashGenerator->generateHashValue($this->xmlWriter, $hashElementName, $hashValue);
260 }
261
269 public function serializeBool($boolValue)
270 {
271 return $boolValue ? 'true' : 'false';
272 }
273 }
eZ\Publish\Core\REST\Common\Output\Generator\Xml
Xml generator.
Definition: Output/Generator/Xml.php:15
eZ\Publish\Core\REST\Common\Output\Generator\Xml\endValueElement
endValueElement($name)
End value element.
Definition: Output/Generator/Xml.php:184
eZ\Publish\Core\REST\Common\Output\Generator\Xml\startAttribute
startAttribute($name, $value)
Start attribute.
Definition: Output/Generator/Xml.php:217
eZ\Publish\Core\REST\Common\Output\Generator\Xml\startValueElement
startValueElement($name, $value, $attributes=[])
Start value element.
Definition: Output/Generator/Xml.php:164
eZ\Publish\Core\REST\Common\Output\Generator\Xml\endObjectElement
endObjectElement($name)
End object element.
Definition: Output/Generator/Xml.php:124
eZ\Publish\Core\REST\Common\Output\Generator\Xml\startDocument
startDocument($data)
Start document.
Definition: Output/Generator/Xml.php:59
eZ\Publish\Core\REST\Common\Output\Generator\Xml\startList
startList($name)
Start list.
Definition: Output/Generator/Xml.php:196
eZ\Publish\Core\REST\Common\Output\Generator\Xml\isEmpty
isEmpty()
Returns if the document is empty or already contains data.
Definition: Output/Generator/Xml.php:76
eZ\Publish\Core\REST\Common\Output\Generator\Xml\generateFieldTypeHash
generateFieldTypeHash($hashElementName, $hashValue)
Generates a generic representation of the scalar, hash or list given in $hashValue into the document,...
Definition: Output/Generator/Xml.php:257
eZ\Publish\Core\REST\Common\Output\Generator\Xml\startObjectElement
startObjectElement($name, $mediaTypeName=null)
Start object element.
Definition: Output/Generator/Xml.php:105
eZ\Publish\Core\REST\Common\Output\Generator\Xml\$vendor
$vendor
Definition: Output/Generator/Xml.php:42
eZ\Publish\Core\REST\Common\Output\Generator\Xml\startHashElement
startHashElement($name)
Start hash element.
Definition: Output/Generator/Xml.php:136
eZ\Publish\Core\REST\Common\Output\Generator\Xml\$xmlWriter
$xmlWriter
Definition: Output/Generator/Xml.php:21
eZ\Publish\Core\REST\Common\Output\Generator\Xml\__construct
__construct(Xml\FieldTypeHashGenerator $hashGenerator, $vendor='vnd.ez.api')
Definition: Output/Generator/Xml.php:48
eZ\Publish\Core\REST\Common\Output\Generator\Xml\getMediaType
getMediaType($name)
Get media type.
Definition: Output/Generator/Xml.php:244
eZ\Publish\Core\REST\Common\Output\Generator\Xml\endHashElement
endHashElement($name)
End hash element.
Definition: Output/Generator/Xml.php:150
eZ\Publish\Core\REST\Common\Output\Generator\Xml\serializeBool
serializeBool($boolValue)
Serializes a boolean value.
Definition: Output/Generator/Xml.php:269
eZ\Publish\Core\REST\Common\Output\Generator\Xml\endAttribute
endAttribute($name)
End attribute.
Definition: Output/Generator/Xml.php:230
eZ\Publish\Core\REST\Common\Output\Generator\Xml\$isEmpty
$isEmpty
Definition: Output/Generator/Xml.php:35
eZ\Publish\Core\REST\Common\Output\Generator\Xml\endList
endList($name)
End list.
Definition: Output/Generator/Xml.php:206
eZ\Publish\Core\REST\Common\Output\Generator\Xml\$hashGenerator
$hashGenerator
Definition: Output/Generator/Xml.php:28
eZ\Publish\Core\REST\Common\Output\Generator\Xml\endDocument
endDocument($data)
End document.
Definition: Output/Generator/Xml.php:90
eZ\Publish\Core\REST\Common\Output\Generator
Output generator.
Definition: REST/Common/Output/Generator.php:13
eZ\Publish\Core\REST\Common\Output\Generator\checkStartDocument
checkStartDocument($data)
Check start document.
Definition: REST/Common/Output/Generator.php:64
eZ\Publish\Core\REST\Common\Output\Generator\checkEndList
checkEndList($data)
Check end list.
Definition: REST/Common/Output/Generator.php:251
eZ\Publish\Core\REST\Common\Output\Generator\checkStartList
checkStartList($data)
Check start list.
Definition: REST/Common/Output/Generator.php:234
eZ\Publish\Core\REST\Common\Output\Generator\checkEndAttribute
checkEndAttribute($data)
Check end attribute.
Definition: REST/Common/Output/Generator.php:286
eZ\Publish\Core\REST\Common\Output\Generator\generateMediaTypeWithVendor
generateMediaTypeWithVendor($name, $type, $vendor='vnd.ez.api')
Generates a media type from $name, $type and $vendor.
Definition: REST/Common/Output/Generator.php:324
eZ\Publish\Core\REST\Common\Output\Generator\checkEndDocument
checkEndDocument($data)
Check end document.
Definition: REST/Common/Output/Generator.php:91
eZ\Publish\Core\REST\Common\Output\Generator\checkEndObjectElement
checkEndObjectElement($data)
Check end object element.
Definition: REST/Common/Output/Generator.php:137
eZ\Publish\Core\REST\Common\Output\Generator\checkStartValueElement
checkStartValueElement($data)
Check start value element.
Definition: REST/Common/Output/Generator.php:200
eZ\Publish\Core\REST\Common\Output\Generator\checkEndValueElement
checkEndValueElement($data)
Check end value element.
Definition: REST/Common/Output/Generator.php:217
eZ\Publish\Core\REST\Common\Output\Generator\checkEndHashElement
checkEndHashElement($data)
Check end hash element.
Definition: REST/Common/Output/Generator.php:182
eZ\Publish\Core\REST\Common\Output\Generator\checkStartAttribute
checkStartAttribute($data)
Check start attribute.
Definition: REST/Common/Output/Generator.php:269
eZ\Publish\Core\REST\Common\Output\Generator\checkStartHashElement
checkStartHashElement($data)
Check start hash element.
Definition: REST/Common/Output/Generator.php:154
eZ\Publish\Core\REST\Common\Output\Generator\checkStartObjectElement
checkStartObjectElement($data)
Check start object element.
Definition: REST/Common/Output/Generator.php:109
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.