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