11
11
12
12
namespace Symfony \Component \VarDumper \Caster ;
13
13
14
+ use Symfony \Component \VarDumper \Cloner \Stub ;
15
+
14
16
/**
15
17
* Casts DOM related classes to array representation.
16
18
*
@@ -38,16 +40,37 @@ class DOMCaster
38
40
DOM_VALIDATION_ERR => 'DOM_VALIDATION_ERR ' ,
39
41
);
40
42
41
- public static function castException (\DOMException $ e , array $ a , $ isNested , &$ cut )
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 )
42
65
{
43
66
if (isset ($ a ["\0* \0code " ], self ::$ errorCodes [$ a ["\0* \0code " ]])) {
44
- $ a ["\0* \0code " ] .= ' ( ' . self ::$ errorCodes [$ a ["\0* \0code " ]]. ' ) ' ;
67
+ $ a ["\0* \0code " ] = new CasterStub ( self ::$ errorCodes [$ a ["\0* \0code " ]], ' const ' ) ;
45
68
}
46
69
47
70
return $ a ;
48
71
}
49
72
50
- public static function castLength ($ dom , array $ a , $ isNested , & $ cut )
73
+ public static function castLength ($ dom , array $ a , Stub $ stub , $ isNested )
51
74
{
52
75
$ a += array (
53
76
'length ' => $ dom ->length ,
@@ -56,7 +79,7 @@ public static function castLength($dom, array $a, $isNested, &$cut)
56
79
return $ a ;
57
80
}
58
81
59
- public static function castImplementation ($ dom , array $ a , $ isNested , & $ cut )
82
+ public static function castImplementation ($ dom , array $ a , Stub $ stub , $ isNested )
60
83
{
61
84
$ a += array (
62
85
"\0~ \0Core " => '1.0 ' ,
@@ -66,61 +89,57 @@ public static function castImplementation($dom, array $a, $isNested, &$cut)
66
89
return $ a ;
67
90
}
68
91
69
- public static function castNode (\DOMNode $ dom , array $ a , $ isNested , & $ cut )
92
+ public static function castNode (\DOMNode $ dom , array $ a , Stub $ stub , $ isNested )
70
93
{
71
- // Commented lines denote properties that exist but are better not dumped for clarity.
72
-
73
94
$ a += array (
74
95
'nodeName ' => $ dom ->nodeName ,
75
- // 'nodeValue' => $dom->nodeValue,
76
- 'nodeType ' => $ dom ->nodeType ,
77
- // 'parentNode' => $dom->parentNode,
96
+ 'nodeValue ' => new CasterStub ( $ dom ->nodeValue ) ,
97
+ 'nodeType ' => new CasterStub ( self :: $ nodeTypes [ $ dom ->nodeType ], ' const ' ) ,
98
+ 'parentNode ' => new CasterStub ( $ dom ->parentNode ) ,
78
99
'childNodes ' => $ dom ->childNodes ,
79
- // 'firstChild' => $dom->firstChild,
80
- // 'lastChild' => $dom->lastChild,
81
- // 'previousSibling' => $dom->previousSibling,
82
- // 'nextSibling' => $dom->nextSibling,
100
+ 'firstChild ' => new CasterStub ( $ dom ->firstChild ) ,
101
+ 'lastChild ' => new CasterStub ( $ dom ->lastChild ) ,
102
+ 'previousSibling ' => new CasterStub ( $ dom ->previousSibling ) ,
103
+ 'nextSibling ' => new CasterStub ( $ dom ->nextSibling ) ,
83
104
'attributes ' => $ dom ->attributes ,
84
- // 'ownerDocument' => $dom->ownerDocument,
105
+ 'ownerDocument ' => new CasterStub ( $ dom ->ownerDocument ) ,
85
106
'namespaceURI ' => $ dom ->namespaceURI ,
86
107
'prefix ' => $ dom ->prefix ,
87
108
'localName ' => $ dom ->localName ,
88
109
'baseURI ' => $ dom ->baseURI ,
89
- // 'textContent' => $dom->textContent,
110
+ 'textContent ' => new CasterStub ( $ dom ->textContent ) ,
90
111
);
91
- $ cut += 8 ;
92
112
93
113
return $ a ;
94
114
}
95
115
96
- public static function castNameSpaceNode (\DOMNameSpaceNode $ dom , array $ a , $ isNested , & $ cut )
116
+ public static function castNameSpaceNode (\DOMNameSpaceNode $ dom , array $ a , Stub $ stub , $ isNested )
97
117
{
98
118
// Commented lines denote properties that exist but are better not dumped for clarity.
99
119
100
120
$ a += array (
101
121
'nodeName ' => $ dom ->nodeName ,
102
- // 'nodeValue' => $dom->nodeValue,
103
- 'nodeType ' => $ dom ->nodeType ,
122
+ 'nodeValue ' => new CasterStub ( $ dom ->nodeValue ) ,
123
+ 'nodeType ' => new CasterStub ( self :: $ nodeTypes [ $ dom ->nodeType ], ' const ' ) ,
104
124
'prefix ' => $ dom ->prefix ,
105
125
'localName ' => $ dom ->localName ,
106
126
'namespaceURI ' => $ dom ->namespaceURI ,
107
- // 'ownerDocument' => $dom->ownerDocument,
108
- // 'parentNode' => $dom->parentNode,
127
+ 'ownerDocument ' => new CasterStub ( $ dom ->ownerDocument ) ,
128
+ 'parentNode ' => new CasterStub ( $ dom ->parentNode ) ,
109
129
);
110
- $ cut += 3 ;
111
130
112
131
return $ a ;
113
132
}
114
133
115
- public static function castDocument (\DOMDocument $ dom , array $ a , $ isNested , & $ cut )
134
+ public static function castDocument (\DOMDocument $ dom , array $ a , Stub $ stub , $ isNested )
116
135
{
117
136
$ formatOutput = $ dom ->formatOutput ;
118
137
$ dom ->formatOutput = true ;
119
138
120
139
$ a += array (
121
140
'doctype ' => $ dom ->doctype ,
122
141
'implementation ' => $ dom ->implementation ,
123
- 'documentElement ' => $ dom ->documentElement ,
142
+ 'documentElement ' => new CasterStub ( $ dom ->documentElement ) ,
124
143
'actualEncoding ' => $ dom ->actualEncoding ,
125
144
'encoding ' => $ dom ->encoding ,
126
145
'xmlEncoding ' => $ dom ->xmlEncoding ,
@@ -145,7 +164,7 @@ public static function castDocument(\DOMDocument $dom, array $a, $isNested, &$cu
145
164
return $ a ;
146
165
}
147
166
148
- public static function castCharacterData (\DOMCharacterData $ dom , array $ a , $ isNested , & $ cut )
167
+ public static function castCharacterData (\DOMCharacterData $ dom , array $ a , Stub $ stub , $ isNested )
149
168
{
150
169
$ a += array (
151
170
'data ' => $ dom ->data ,
@@ -155,7 +174,7 @@ public static function castCharacterData(\DOMCharacterData $dom, array $a, $isNe
155
174
return $ a ;
156
175
}
157
176
158
- public static function castAttr (\DOMAttr $ dom , array $ a , $ isNested , & $ cut )
177
+ public static function castAttr (\DOMAttr $ dom , array $ a , Stub $ stub , $ isNested )
159
178
{
160
179
$ a += array (
161
180
'name ' => $ dom ->name ,
@@ -168,7 +187,7 @@ public static function castAttr(\DOMAttr $dom, array $a, $isNested, &$cut)
168
187
return $ a ;
169
188
}
170
189
171
- public static function castElement (\DOMElement $ dom , array $ a , $ isNested , & $ cut )
190
+ public static function castElement (\DOMElement $ dom , array $ a , Stub $ stub , $ isNested )
172
191
{
173
192
$ a += array (
174
193
'tagName ' => $ dom ->tagName ,
@@ -178,7 +197,7 @@ public static function castElement(\DOMElement $dom, array $a, $isNested, &$cut)
178
197
return $ a ;
179
198
}
180
199
181
- public static function castText (\DOMText $ dom , array $ a , $ isNested , & $ cut )
200
+ public static function castText (\DOMText $ dom , array $ a , Stub $ stub , $ isNested )
182
201
{
183
202
$ a += array (
184
203
'wholeText ' => $ dom ->wholeText ,
@@ -187,7 +206,7 @@ public static function castText(\DOMText $dom, array $a, $isNested, &$cut)
187
206
return $ a ;
188
207
}
189
208
190
- public static function castTypeinfo (\DOMTypeinfo $ dom , array $ a , $ isNested , & $ cut )
209
+ public static function castTypeinfo (\DOMTypeinfo $ dom , array $ a , Stub $ stub , $ isNested )
191
210
{
192
211
$ a += array (
193
212
'typeName ' => $ dom ->typeName ,
@@ -197,7 +216,7 @@ public static function castTypeinfo(\DOMTypeinfo $dom, array $a, $isNested, &$cu
197
216
return $ a ;
198
217
}
199
218
200
- public static function castDomError (\DOMDomError $ dom , array $ a , $ isNested , & $ cut )
219
+ public static function castDomError (\DOMDomError $ dom , array $ a , Stub $ stub , $ isNested )
201
220
{
202
221
$ a += array (
203
222
'severity ' => $ dom ->severity ,
@@ -211,7 +230,7 @@ public static function castDomError(\DOMDomError $dom, array $a, $isNested, &$cu
211
230
return $ a ;
212
231
}
213
232
214
- public static function castLocator (\DOMLocator $ dom , array $ a , $ isNested , & $ cut )
233
+ public static function castLocator (\DOMLocator $ dom , array $ a , Stub $ stub , $ isNested )
215
234
{
216
235
$ a += array (
217
236
'lineNumber ' => $ dom ->lineNumber ,
@@ -224,7 +243,7 @@ public static function castLocator(\DOMLocator $dom, array $a, $isNested, &$cut)
224
243
return $ a ;
225
244
}
226
245
227
- public static function castDocumentType (\DOMDocumentType $ dom , array $ a , $ isNested , & $ cut )
246
+ public static function castDocumentType (\DOMDocumentType $ dom , array $ a , Stub $ stub , $ isNested )
228
247
{
229
248
$ a += array (
230
249
'name ' => $ dom ->name ,
@@ -238,7 +257,7 @@ public static function castDocumentType(\DOMDocumentType $dom, array $a, $isNest
238
257
return $ a ;
239
258
}
240
259
241
- public static function castNotation (\DOMNotation $ dom , array $ a , $ isNested , & $ cut )
260
+ public static function castNotation (\DOMNotation $ dom , array $ a , Stub $ stub , $ isNested )
242
261
{
243
262
$ a += array (
244
263
'publicId ' => $ dom ->publicId ,
@@ -248,7 +267,7 @@ public static function castNotation(\DOMNotation $dom, array $a, $isNested, &$cu
248
267
return $ a ;
249
268
}
250
269
251
- public static function castEntity (\DOMEntity $ dom , array $ a , $ isNested , & $ cut )
270
+ public static function castEntity (\DOMEntity $ dom , array $ a , Stub $ stub , $ isNested )
252
271
{
253
272
$ a += array (
254
273
'publicId ' => $ dom ->publicId ,
@@ -262,7 +281,7 @@ public static function castEntity(\DOMEntity $dom, array $a, $isNested, &$cut)
262
281
return $ a ;
263
282
}
264
283
265
- public static function castProcessingInstruction (\DOMProcessingInstruction $ dom , array $ a , $ isNested , & $ cut )
284
+ public static function castProcessingInstruction (\DOMProcessingInstruction $ dom , array $ a , Stub $ stub , $ isNested )
266
285
{
267
286
$ a += array (
268
287
'target ' => $ dom ->target ,
@@ -272,7 +291,7 @@ public static function castProcessingInstruction(\DOMProcessingInstruction $dom,
272
291
return $ a ;
273
292
}
274
293
275
- public static function castXPath (\DOMXPath $ dom , array $ a , $ isNested , & $ cut )
294
+ public static function castXPath (\DOMXPath $ dom , array $ a , Stub $ stub , $ isNested )
276
295
{
277
296
$ a += array (
278
297
'document ' => $ dom ->document ,
0 commit comments