Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / var-dumper / Caster / DOMCaster.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\VarDumper\Caster;
13
14 use Symfony\Component\VarDumper\Cloner\Stub;
15
16 /**
17  * Casts DOM related classes to array representation.
18  *
19  * @author Nicolas Grekas <p@tchwork.com>
20  */
21 class DOMCaster
22 {
23     private static $errorCodes = array(
24         DOM_PHP_ERR => 'DOM_PHP_ERR',
25         DOM_INDEX_SIZE_ERR => 'DOM_INDEX_SIZE_ERR',
26         DOMSTRING_SIZE_ERR => 'DOMSTRING_SIZE_ERR',
27         DOM_HIERARCHY_REQUEST_ERR => 'DOM_HIERARCHY_REQUEST_ERR',
28         DOM_WRONG_DOCUMENT_ERR => 'DOM_WRONG_DOCUMENT_ERR',
29         DOM_INVALID_CHARACTER_ERR => 'DOM_INVALID_CHARACTER_ERR',
30         DOM_NO_DATA_ALLOWED_ERR => 'DOM_NO_DATA_ALLOWED_ERR',
31         DOM_NO_MODIFICATION_ALLOWED_ERR => 'DOM_NO_MODIFICATION_ALLOWED_ERR',
32         DOM_NOT_FOUND_ERR => 'DOM_NOT_FOUND_ERR',
33         DOM_NOT_SUPPORTED_ERR => 'DOM_NOT_SUPPORTED_ERR',
34         DOM_INUSE_ATTRIBUTE_ERR => 'DOM_INUSE_ATTRIBUTE_ERR',
35         DOM_INVALID_STATE_ERR => 'DOM_INVALID_STATE_ERR',
36         DOM_SYNTAX_ERR => 'DOM_SYNTAX_ERR',
37         DOM_INVALID_MODIFICATION_ERR => 'DOM_INVALID_MODIFICATION_ERR',
38         DOM_NAMESPACE_ERR => 'DOM_NAMESPACE_ERR',
39         DOM_INVALID_ACCESS_ERR => 'DOM_INVALID_ACCESS_ERR',
40         DOM_VALIDATION_ERR => 'DOM_VALIDATION_ERR',
41     );
42
43     private static $nodeTypes = array(
44         XML_ELEMENT_NODE => 'XML_ELEMENT_NODE',
45         XML_ATTRIBUTE_NODE => 'XML_ATTRIBUTE_NODE',
46         XML_TEXT_NODE => 'XML_TEXT_NODE',
47         XML_CDATA_SECTION_NODE => 'XML_CDATA_SECTION_NODE',
48         XML_ENTITY_REF_NODE => 'XML_ENTITY_REF_NODE',
49         XML_ENTITY_NODE => 'XML_ENTITY_NODE',
50         XML_PI_NODE => 'XML_PI_NODE',
51         XML_COMMENT_NODE => 'XML_COMMENT_NODE',
52         XML_DOCUMENT_NODE => 'XML_DOCUMENT_NODE',
53         XML_DOCUMENT_TYPE_NODE => 'XML_DOCUMENT_TYPE_NODE',
54         XML_DOCUMENT_FRAG_NODE => 'XML_DOCUMENT_FRAG_NODE',
55         XML_NOTATION_NODE => 'XML_NOTATION_NODE',
56         XML_HTML_DOCUMENT_NODE => 'XML_HTML_DOCUMENT_NODE',
57         XML_DTD_NODE => 'XML_DTD_NODE',
58         XML_ELEMENT_DECL_NODE => 'XML_ELEMENT_DECL_NODE',
59         XML_ATTRIBUTE_DECL_NODE => 'XML_ATTRIBUTE_DECL_NODE',
60         XML_ENTITY_DECL_NODE => 'XML_ENTITY_DECL_NODE',
61         XML_NAMESPACE_DECL_NODE => 'XML_NAMESPACE_DECL_NODE',
62     );
63
64     public static function castException(\DOMException $e, array $a, Stub $stub, $isNested)
65     {
66         $k = Caster::PREFIX_PROTECTED.'code';
67         if (isset($a[$k], self::$errorCodes[$a[$k]])) {
68             $a[$k] = new ConstStub(self::$errorCodes[$a[$k]], $a[$k]);
69         }
70
71         return $a;
72     }
73
74     public static function castLength($dom, array $a, Stub $stub, $isNested)
75     {
76         $a += array(
77             'length' => $dom->length,
78         );
79
80         return $a;
81     }
82
83     public static function castImplementation($dom, array $a, Stub $stub, $isNested)
84     {
85         $a += array(
86             Caster::PREFIX_VIRTUAL.'Core' => '1.0',
87             Caster::PREFIX_VIRTUAL.'XML' => '2.0',
88         );
89
90         return $a;
91     }
92
93     public static function castNode(\DOMNode $dom, array $a, Stub $stub, $isNested)
94     {
95         $a += array(
96             'nodeName' => $dom->nodeName,
97             'nodeValue' => new CutStub($dom->nodeValue),
98             'nodeType' => new ConstStub(self::$nodeTypes[$dom->nodeType], $dom->nodeType),
99             'parentNode' => new CutStub($dom->parentNode),
100             'childNodes' => $dom->childNodes,
101             'firstChild' => new CutStub($dom->firstChild),
102             'lastChild' => new CutStub($dom->lastChild),
103             'previousSibling' => new CutStub($dom->previousSibling),
104             'nextSibling' => new CutStub($dom->nextSibling),
105             'attributes' => $dom->attributes,
106             'ownerDocument' => new CutStub($dom->ownerDocument),
107             'namespaceURI' => $dom->namespaceURI,
108             'prefix' => $dom->prefix,
109             'localName' => $dom->localName,
110             'baseURI' => $dom->baseURI ? new LinkStub($dom->baseURI) : $dom->baseURI,
111             'textContent' => new CutStub($dom->textContent),
112         );
113
114         return $a;
115     }
116
117     public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub $stub, $isNested)
118     {
119         $a += array(
120             'nodeName' => $dom->nodeName,
121             'nodeValue' => new CutStub($dom->nodeValue),
122             'nodeType' => new ConstStub(self::$nodeTypes[$dom->nodeType], $dom->nodeType),
123             'prefix' => $dom->prefix,
124             'localName' => $dom->localName,
125             'namespaceURI' => $dom->namespaceURI,
126             'ownerDocument' => new CutStub($dom->ownerDocument),
127             'parentNode' => new CutStub($dom->parentNode),
128         );
129
130         return $a;
131     }
132
133     public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $isNested, $filter = 0)
134     {
135         $a += array(
136             'doctype' => $dom->doctype,
137             'implementation' => $dom->implementation,
138             'documentElement' => new CutStub($dom->documentElement),
139             'actualEncoding' => $dom->actualEncoding,
140             'encoding' => $dom->encoding,
141             'xmlEncoding' => $dom->xmlEncoding,
142             'standalone' => $dom->standalone,
143             'xmlStandalone' => $dom->xmlStandalone,
144             'version' => $dom->version,
145             'xmlVersion' => $dom->xmlVersion,
146             'strictErrorChecking' => $dom->strictErrorChecking,
147             'documentURI' => $dom->documentURI ? new LinkStub($dom->documentURI) : $dom->documentURI,
148             'config' => $dom->config,
149             'formatOutput' => $dom->formatOutput,
150             'validateOnParse' => $dom->validateOnParse,
151             'resolveExternals' => $dom->resolveExternals,
152             'preserveWhiteSpace' => $dom->preserveWhiteSpace,
153             'recover' => $dom->recover,
154             'substituteEntities' => $dom->substituteEntities,
155         );
156
157         if (!($filter & Caster::EXCLUDE_VERBOSE)) {
158             $formatOutput = $dom->formatOutput;
159             $dom->formatOutput = true;
160             $a += array(Caster::PREFIX_VIRTUAL.'xml' => $dom->saveXML());
161             $dom->formatOutput = $formatOutput;
162         }
163
164         return $a;
165     }
166
167     public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub $stub, $isNested)
168     {
169         $a += array(
170             'data' => $dom->data,
171             'length' => $dom->length,
172         );
173
174         return $a;
175     }
176
177     public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, $isNested)
178     {
179         $a += array(
180             'name' => $dom->name,
181             'specified' => $dom->specified,
182             'value' => $dom->value,
183             'ownerElement' => $dom->ownerElement,
184             'schemaTypeInfo' => $dom->schemaTypeInfo,
185         );
186
187         return $a;
188     }
189
190     public static function castElement(\DOMElement $dom, array $a, Stub $stub, $isNested)
191     {
192         $a += array(
193             'tagName' => $dom->tagName,
194             'schemaTypeInfo' => $dom->schemaTypeInfo,
195         );
196
197         return $a;
198     }
199
200     public static function castText(\DOMText $dom, array $a, Stub $stub, $isNested)
201     {
202         $a += array(
203             'wholeText' => $dom->wholeText,
204         );
205
206         return $a;
207     }
208
209     public static function castTypeinfo(\DOMTypeinfo $dom, array $a, Stub $stub, $isNested)
210     {
211         $a += array(
212             'typeName' => $dom->typeName,
213             'typeNamespace' => $dom->typeNamespace,
214         );
215
216         return $a;
217     }
218
219     public static function castDomError(\DOMDomError $dom, array $a, Stub $stub, $isNested)
220     {
221         $a += array(
222             'severity' => $dom->severity,
223             'message' => $dom->message,
224             'type' => $dom->type,
225             'relatedException' => $dom->relatedException,
226             'related_data' => $dom->related_data,
227             'location' => $dom->location,
228         );
229
230         return $a;
231     }
232
233     public static function castLocator(\DOMLocator $dom, array $a, Stub $stub, $isNested)
234     {
235         $a += array(
236             'lineNumber' => $dom->lineNumber,
237             'columnNumber' => $dom->columnNumber,
238             'offset' => $dom->offset,
239             'relatedNode' => $dom->relatedNode,
240             'uri' => $dom->uri ? new LinkStub($dom->uri, $dom->lineNumber) : $dom->uri,
241         );
242
243         return $a;
244     }
245
246     public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $stub, $isNested)
247     {
248         $a += array(
249             'name' => $dom->name,
250             'entities' => $dom->entities,
251             'notations' => $dom->notations,
252             'publicId' => $dom->publicId,
253             'systemId' => $dom->systemId,
254             'internalSubset' => $dom->internalSubset,
255         );
256
257         return $a;
258     }
259
260     public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, $isNested)
261     {
262         $a += array(
263             'publicId' => $dom->publicId,
264             'systemId' => $dom->systemId,
265         );
266
267         return $a;
268     }
269
270     public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, $isNested)
271     {
272         $a += array(
273             'publicId' => $dom->publicId,
274             'systemId' => $dom->systemId,
275             'notationName' => $dom->notationName,
276             'actualEncoding' => $dom->actualEncoding,
277             'encoding' => $dom->encoding,
278             'version' => $dom->version,
279         );
280
281         return $a;
282     }
283
284     public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, Stub $stub, $isNested)
285     {
286         $a += array(
287             'target' => $dom->target,
288             'data' => $dom->data,
289         );
290
291         return $a;
292     }
293
294     public static function castXPath(\DOMXPath $dom, array $a, Stub $stub, $isNested)
295     {
296         $a += array(
297             'document' => $dom->document,
298         );
299
300         return $a;
301     }
302 }