4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\VarDumper\Caster;
14 use Symfony\Component\VarDumper\Cloner\Stub;
17 * Casts DOM related classes to array representation.
19 * @author Nicolas Grekas <p@tchwork.com>
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',
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',
64 public static function castException(\DOMException $e, array $a, Stub $stub, $isNested)
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]);
74 public static function castLength($dom, array $a, Stub $stub, $isNested)
77 'length' => $dom->length,
83 public static function castImplementation($dom, array $a, Stub $stub, $isNested)
86 Caster::PREFIX_VIRTUAL.'Core' => '1.0',
87 Caster::PREFIX_VIRTUAL.'XML' => '2.0',
93 public static function castNode(\DOMNode $dom, array $a, Stub $stub, $isNested)
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,
111 'textContent' => new CutStub($dom->textContent),
117 public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub $stub, $isNested)
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),
133 public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $isNested, $filter = 0)
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,
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,
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;
167 public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub $stub, $isNested)
170 'data' => $dom->data,
171 'length' => $dom->length,
177 public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, $isNested)
180 'name' => $dom->name,
181 'specified' => $dom->specified,
182 'value' => $dom->value,
183 'ownerElement' => $dom->ownerElement,
184 'schemaTypeInfo' => $dom->schemaTypeInfo,
190 public static function castElement(\DOMElement $dom, array $a, Stub $stub, $isNested)
193 'tagName' => $dom->tagName,
194 'schemaTypeInfo' => $dom->schemaTypeInfo,
200 public static function castText(\DOMText $dom, array $a, Stub $stub, $isNested)
203 'wholeText' => $dom->wholeText,
209 public static function castTypeinfo(\DOMTypeinfo $dom, array $a, Stub $stub, $isNested)
212 'typeName' => $dom->typeName,
213 'typeNamespace' => $dom->typeNamespace,
219 public static function castDomError(\DOMDomError $dom, array $a, Stub $stub, $isNested)
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,
233 public static function castLocator(\DOMLocator $dom, array $a, Stub $stub, $isNested)
236 'lineNumber' => $dom->lineNumber,
237 'columnNumber' => $dom->columnNumber,
238 'offset' => $dom->offset,
239 'relatedNode' => $dom->relatedNode,
246 public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $stub, $isNested)
249 'name' => $dom->name,
250 'entities' => $dom->entities,
251 'notations' => $dom->notations,
252 'publicId' => $dom->publicId,
253 'systemId' => $dom->systemId,
254 'internalSubset' => $dom->internalSubset,
260 public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, $isNested)
263 'publicId' => $dom->publicId,
264 'systemId' => $dom->systemId,
270 public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, $isNested)
273 'publicId' => $dom->publicId,
274 'systemId' => $dom->systemId,
275 'notationName' => $dom->notationName,
276 'actualEncoding' => $dom->actualEncoding,
277 'encoding' => $dom->encoding,
278 'version' => $dom->version,
284 public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, Stub $stub, $isNested)
287 'target' => $dom->target,
288 'data' => $dom->data,
294 public static function castXPath(\DOMXPath $dom, array $a, Stub $stub, $isNested)
297 'document' => $dom->document,