Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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
 * @final
22
 */
23
class DOMCaster
24
{
25
    private const ERROR_CODES = [
26
        \DOM_PHP_ERR => 'DOM_PHP_ERR',
27
        \DOM_INDEX_SIZE_ERR => 'DOM_INDEX_SIZE_ERR',
28
        \DOMSTRING_SIZE_ERR => 'DOMSTRING_SIZE_ERR',
29
        \DOM_HIERARCHY_REQUEST_ERR => 'DOM_HIERARCHY_REQUEST_ERR',
30
        \DOM_WRONG_DOCUMENT_ERR => 'DOM_WRONG_DOCUMENT_ERR',
31
        \DOM_INVALID_CHARACTER_ERR => 'DOM_INVALID_CHARACTER_ERR',
32
        \DOM_NO_DATA_ALLOWED_ERR => 'DOM_NO_DATA_ALLOWED_ERR',
33
        \DOM_NO_MODIFICATION_ALLOWED_ERR => 'DOM_NO_MODIFICATION_ALLOWED_ERR',
34
        \DOM_NOT_FOUND_ERR => 'DOM_NOT_FOUND_ERR',
35
        \DOM_NOT_SUPPORTED_ERR => 'DOM_NOT_SUPPORTED_ERR',
36
        \DOM_INUSE_ATTRIBUTE_ERR => 'DOM_INUSE_ATTRIBUTE_ERR',
37
        \DOM_INVALID_STATE_ERR => 'DOM_INVALID_STATE_ERR',
38
        \DOM_SYNTAX_ERR => 'DOM_SYNTAX_ERR',
39
        \DOM_INVALID_MODIFICATION_ERR => 'DOM_INVALID_MODIFICATION_ERR',
40
        \DOM_NAMESPACE_ERR => 'DOM_NAMESPACE_ERR',
41
        \DOM_INVALID_ACCESS_ERR => 'DOM_INVALID_ACCESS_ERR',
42
        \DOM_VALIDATION_ERR => 'DOM_VALIDATION_ERR',
43
    ];
44
 
45
    private const NODE_TYPES = [
46
        \XML_ELEMENT_NODE => 'XML_ELEMENT_NODE',
47
        \XML_ATTRIBUTE_NODE => 'XML_ATTRIBUTE_NODE',
48
        \XML_TEXT_NODE => 'XML_TEXT_NODE',
49
        \XML_CDATA_SECTION_NODE => 'XML_CDATA_SECTION_NODE',
50
        \XML_ENTITY_REF_NODE => 'XML_ENTITY_REF_NODE',
51
        \XML_ENTITY_NODE => 'XML_ENTITY_NODE',
52
        \XML_PI_NODE => 'XML_PI_NODE',
53
        \XML_COMMENT_NODE => 'XML_COMMENT_NODE',
54
        \XML_DOCUMENT_NODE => 'XML_DOCUMENT_NODE',
55
        \XML_DOCUMENT_TYPE_NODE => 'XML_DOCUMENT_TYPE_NODE',
56
        \XML_DOCUMENT_FRAG_NODE => 'XML_DOCUMENT_FRAG_NODE',
57
        \XML_NOTATION_NODE => 'XML_NOTATION_NODE',
58
        \XML_HTML_DOCUMENT_NODE => 'XML_HTML_DOCUMENT_NODE',
59
        \XML_DTD_NODE => 'XML_DTD_NODE',
60
        \XML_ELEMENT_DECL_NODE => 'XML_ELEMENT_DECL_NODE',
61
        \XML_ATTRIBUTE_DECL_NODE => 'XML_ATTRIBUTE_DECL_NODE',
62
        \XML_ENTITY_DECL_NODE => 'XML_ENTITY_DECL_NODE',
63
        \XML_NAMESPACE_DECL_NODE => 'XML_NAMESPACE_DECL_NODE',
64
    ];
65
 
66
    public static function castException(\DOMException $e, array $a, Stub $stub, bool $isNested)
67
    {
68
        $k = Caster::PREFIX_PROTECTED.'code';
69
        if (isset($a[$k], self::ERROR_CODES[$a[$k]])) {
70
            $a[$k] = new ConstStub(self::ERROR_CODES[$a[$k]], $a[$k]);
71
        }
72
 
73
        return $a;
74
    }
75
 
76
    public static function castLength($dom, array $a, Stub $stub, bool $isNested)
77
    {
78
        $a += [
79
            'length' => $dom->length,
80
        ];
81
 
82
        return $a;
83
    }
84
 
85
    public static function castImplementation(\DOMImplementation $dom, array $a, Stub $stub, bool $isNested)
86
    {
87
        $a += [
88
            Caster::PREFIX_VIRTUAL.'Core' => '1.0',
89
            Caster::PREFIX_VIRTUAL.'XML' => '2.0',
90
        ];
91
 
92
        return $a;
93
    }
94
 
95
    public static function castNode(\DOMNode $dom, array $a, Stub $stub, bool $isNested)
96
    {
97
        $a += [
98
            'nodeName' => $dom->nodeName,
99
            'nodeValue' => new CutStub($dom->nodeValue),
100
            'nodeType' => new ConstStub(self::NODE_TYPES[$dom->nodeType], $dom->nodeType),
101
            'parentNode' => new CutStub($dom->parentNode),
102
            'childNodes' => $dom->childNodes,
103
            'firstChild' => new CutStub($dom->firstChild),
104
            'lastChild' => new CutStub($dom->lastChild),
105
            'previousSibling' => new CutStub($dom->previousSibling),
106
            'nextSibling' => new CutStub($dom->nextSibling),
107
            'attributes' => $dom->attributes,
108
            'ownerDocument' => new CutStub($dom->ownerDocument),
109
            'namespaceURI' => $dom->namespaceURI,
110
            'prefix' => $dom->prefix,
111
            'localName' => $dom->localName,
112
            'baseURI' => $dom->baseURI ? new LinkStub($dom->baseURI) : $dom->baseURI,
113
            'textContent' => new CutStub($dom->textContent),
114
        ];
115
 
116
        return $a;
117
    }
118
 
119
    public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub $stub, bool $isNested)
120
    {
121
        $a += [
122
            'nodeName' => $dom->nodeName,
123
            'nodeValue' => new CutStub($dom->nodeValue),
124
            'nodeType' => new ConstStub(self::NODE_TYPES[$dom->nodeType], $dom->nodeType),
125
            'prefix' => $dom->prefix,
126
            'localName' => $dom->localName,
127
            'namespaceURI' => $dom->namespaceURI,
128
            'ownerDocument' => new CutStub($dom->ownerDocument),
129
            'parentNode' => new CutStub($dom->parentNode),
130
        ];
131
 
132
        return $a;
133
    }
134
 
135
    public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, bool $isNested, int $filter = 0)
136
    {
137
        $a += [
138
            'doctype' => $dom->doctype,
139
            'implementation' => $dom->implementation,
140
            'documentElement' => new CutStub($dom->documentElement),
141
            'actualEncoding' => $dom->actualEncoding,
142
            'encoding' => $dom->encoding,
143
            'xmlEncoding' => $dom->xmlEncoding,
144
            'standalone' => $dom->standalone,
145
            'xmlStandalone' => $dom->xmlStandalone,
146
            'version' => $dom->version,
147
            'xmlVersion' => $dom->xmlVersion,
148
            'strictErrorChecking' => $dom->strictErrorChecking,
149
            'documentURI' => $dom->documentURI ? new LinkStub($dom->documentURI) : $dom->documentURI,
150
            'config' => $dom->config,
151
            'formatOutput' => $dom->formatOutput,
152
            'validateOnParse' => $dom->validateOnParse,
153
            'resolveExternals' => $dom->resolveExternals,
154
            'preserveWhiteSpace' => $dom->preserveWhiteSpace,
155
            'recover' => $dom->recover,
156
            'substituteEntities' => $dom->substituteEntities,
157
        ];
158
 
159
        if (!($filter & Caster::EXCLUDE_VERBOSE)) {
160
            $formatOutput = $dom->formatOutput;
161
            $dom->formatOutput = true;
162
            $a += [Caster::PREFIX_VIRTUAL.'xml' => $dom->saveXML()];
163
            $dom->formatOutput = $formatOutput;
164
        }
165
 
166
        return $a;
167
    }
168
 
169
    public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub $stub, bool $isNested)
170
    {
171
        $a += [
172
            'data' => $dom->data,
173
            'length' => $dom->length,
174
        ];
175
 
176
        return $a;
177
    }
178
 
179
    public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, bool $isNested)
180
    {
181
        $a += [
182
            'name' => $dom->name,
183
            'specified' => $dom->specified,
184
            'value' => $dom->value,
185
            'ownerElement' => $dom->ownerElement,
186
            'schemaTypeInfo' => $dom->schemaTypeInfo,
187
        ];
188
 
189
        return $a;
190
    }
191
 
192
    public static function castElement(\DOMElement $dom, array $a, Stub $stub, bool $isNested)
193
    {
194
        $a += [
195
            'tagName' => $dom->tagName,
196
            'schemaTypeInfo' => $dom->schemaTypeInfo,
197
        ];
198
 
199
        return $a;
200
    }
201
 
202
    public static function castText(\DOMText $dom, array $a, Stub $stub, bool $isNested)
203
    {
204
        $a += [
205
            'wholeText' => $dom->wholeText,
206
        ];
207
 
208
        return $a;
209
    }
210
 
211
    public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $stub, bool $isNested)
212
    {
213
        $a += [
214
            'name' => $dom->name,
215
            'entities' => $dom->entities,
216
            'notations' => $dom->notations,
217
            'publicId' => $dom->publicId,
218
            'systemId' => $dom->systemId,
219
            'internalSubset' => $dom->internalSubset,
220
        ];
221
 
222
        return $a;
223
    }
224
 
225
    public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, bool $isNested)
226
    {
227
        $a += [
228
            'publicId' => $dom->publicId,
229
            'systemId' => $dom->systemId,
230
        ];
231
 
232
        return $a;
233
    }
234
 
235
    public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, bool $isNested)
236
    {
237
        $a += [
238
            'publicId' => $dom->publicId,
239
            'systemId' => $dom->systemId,
240
            'notationName' => $dom->notationName,
241
            'actualEncoding' => $dom->actualEncoding,
242
            'encoding' => $dom->encoding,
243
            'version' => $dom->version,
244
        ];
245
 
246
        return $a;
247
    }
248
 
249
    public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, Stub $stub, bool $isNested)
250
    {
251
        $a += [
252
            'target' => $dom->target,
253
            'data' => $dom->data,
254
        ];
255
 
256
        return $a;
257
    }
258
 
259
    public static function castXPath(\DOMXPath $dom, array $a, Stub $stub, bool $isNested)
260
    {
261
        $a += [
262
            'document' => $dom->document,
263
        ];
264
 
265
        return $a;
266
    }
267
}