@@ -63,7 +63,7 @@ class DOMCaster
63
63
\XML_NAMESPACE_DECL_NODE => 'XML_NAMESPACE_DECL_NODE ' ,
64
64
];
65
65
66
- public static function castException (\DOMException $ e , array $ a , Stub $ stub , bool $ isNested ): array
66
+ public static function castException (\DOMException | \ DOM \ Exception $ e , array $ a , Stub $ stub , bool $ isNested ): array
67
67
{
68
68
$ k = Caster::PREFIX_PROTECTED .'code ' ;
69
69
if (isset ($ a [$ k ], self ::ERROR_CODES [$ a [$ k ]])) {
@@ -82,7 +82,7 @@ public static function castLength($dom, array $a, Stub $stub, bool $isNested): a
82
82
return $ a ;
83
83
}
84
84
85
- public static function castImplementation (\DOMImplementation $ dom , array $ a , Stub $ stub , bool $ isNested ): array
85
+ public static function castImplementation (\DOMImplementation | \ DOM \ Implementation $ dom , array $ a , Stub $ stub , bool $ isNested ): array
86
86
{
87
87
$ a += [
88
88
Caster::PREFIX_VIRTUAL .'Core ' => '1.0 ' ,
@@ -92,7 +92,7 @@ public static function castImplementation(\DOMImplementation $dom, array $a, Stu
92
92
return $ a ;
93
93
}
94
94
95
- public static function castNode (\DOMNode $ dom , array $ a , Stub $ stub , bool $ isNested ): array
95
+ public static function castNode (\DOMNode | \ DOM \ Node $ dom , array $ a , Stub $ stub , bool $ isNested ): array
96
96
{
97
97
$ a += [
98
98
'nodeName ' => $ dom ->nodeName ,
@@ -104,15 +104,20 @@ public static function castNode(\DOMNode $dom, array $a, Stub $stub, bool $isNes
104
104
'lastChild ' => new CutStub ($ dom ->lastChild ),
105
105
'previousSibling ' => new CutStub ($ dom ->previousSibling ),
106
106
'nextSibling ' => new CutStub ($ dom ->nextSibling ),
107
- 'attributes ' => $ dom ->attributes ,
108
107
'ownerDocument ' => new CutStub ($ dom ->ownerDocument ),
109
- 'namespaceURI ' => $ dom ->namespaceURI ,
110
- 'prefix ' => $ dom ->prefix ,
111
- 'localName ' => $ dom ->localName ,
112
108
'baseURI ' => $ dom ->baseURI ? new LinkStub ($ dom ->baseURI ) : $ dom ->baseURI ,
113
109
'textContent ' => new CutStub ($ dom ->textContent ),
114
110
];
115
111
112
+ if ($ dom instanceof \DOMNode || $ dom instanceof \DOM \Element) {
113
+ $ a += [
114
+ 'attributes ' => $ dom ->attributes ,
115
+ 'namespaceURI ' => $ dom ->namespaceURI ,
116
+ 'prefix ' => $ dom ->prefix ,
117
+ 'localName ' => $ dom ->localName ,
118
+ ];
119
+ }
120
+
116
121
return $ a ;
117
122
}
118
123
@@ -166,7 +171,48 @@ public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, boo
166
171
return $ a ;
167
172
}
168
173
169
- public static function castCharacterData (\DOMCharacterData $ dom , array $ a , Stub $ stub , bool $ isNested ): array
174
+ public static function castXMLDocument (\DOM \XMLDocument $ dom , array $ a , Stub $ stub , bool $ isNested , int $ filter = 0 ): array
175
+ {
176
+ $ a += [
177
+ 'doctype ' => $ dom ->doctype ,
178
+ 'implementation ' => $ dom ->implementation ,
179
+ 'documentElement ' => new CutStub ($ dom ->documentElement ),
180
+ 'inputEncoding ' => $ dom ->inputEncoding ,
181
+ 'xmlEncoding ' => $ dom ->xmlEncoding ,
182
+ 'xmlStandalone ' => $ dom ->xmlStandalone ,
183
+ 'xmlVersion ' => $ dom ->xmlVersion ,
184
+ 'documentURI ' => $ dom ->documentURI ? new LinkStub ($ dom ->documentURI ) : $ dom ->documentURI ,
185
+ 'formatOutput ' => $ dom ->formatOutput ,
186
+ ];
187
+
188
+ if (!($ filter & Caster::EXCLUDE_VERBOSE )) {
189
+ $ formatOutput = $ dom ->formatOutput ;
190
+ $ dom ->formatOutput = true ;
191
+ $ a += [Caster::PREFIX_VIRTUAL .'xml ' => $ dom ->saveXML ()];
192
+ $ dom ->formatOutput = $ formatOutput ;
193
+ }
194
+
195
+ return $ a ;
196
+ }
197
+
198
+ public static function castHTMLDocument (\DOM \HTMLDocument $ dom , array $ a , Stub $ stub , bool $ isNested , int $ filter = 0 ): array
199
+ {
200
+ $ a += [
201
+ 'doctype ' => $ dom ->doctype ,
202
+ 'implementation ' => $ dom ->implementation ,
203
+ 'documentElement ' => new CutStub ($ dom ->documentElement ),
204
+ 'inputEncoding ' => $ dom ->inputEncoding ,
205
+ 'documentURI ' => $ dom ->documentURI ? new LinkStub ($ dom ->documentURI ) : $ dom ->documentURI ,
206
+ ];
207
+
208
+ if (!($ filter & Caster::EXCLUDE_VERBOSE )) {
209
+ $ a += [Caster::PREFIX_VIRTUAL .'html ' => $ dom ->saveHTML ()];
210
+ }
211
+
212
+ return $ a ;
213
+ }
214
+
215
+ public static function castCharacterData (\DOMCharacterData |\DOM \CharacterData $ dom , array $ a , Stub $ stub , bool $ isNested ): array
170
216
{
171
217
$ a += [
172
218
'data ' => $ dom ->data ,
@@ -176,30 +222,40 @@ public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub
176
222
return $ a ;
177
223
}
178
224
179
- public static function castAttr (\DOMAttr $ dom , array $ a , Stub $ stub , bool $ isNested ): array
225
+ public static function castAttr (\DOMAttr | \ DOM \ Attr $ dom , array $ a , Stub $ stub , bool $ isNested ): array
180
226
{
181
227
$ a += [
182
228
'name ' => $ dom ->name ,
183
229
'specified ' => $ dom ->specified ,
184
230
'value ' => $ dom ->value ,
185
231
'ownerElement ' => $ dom ->ownerElement ,
186
- 'schemaTypeInfo ' => $ dom ->schemaTypeInfo ,
187
232
];
188
233
234
+ if ($ dom instanceof \DOMAttr) {
235
+ $ a += [
236
+ 'schemaTypeInfo ' => $ dom ->schemaTypeInfo ,
237
+ ];
238
+ }
239
+
189
240
return $ a ;
190
241
}
191
242
192
- public static function castElement (\DOMElement $ dom , array $ a , Stub $ stub , bool $ isNested ): array
243
+ public static function castElement (\DOMElement | \ DOM \ Element $ dom , array $ a , Stub $ stub , bool $ isNested ): array
193
244
{
194
245
$ a += [
195
246
'tagName ' => $ dom ->tagName ,
196
- 'schemaTypeInfo ' => $ dom ->schemaTypeInfo ,
197
247
];
198
248
249
+ if ($ dom instanceof \DOMElement) {
250
+ $ a += [
251
+ 'schemaTypeInfo ' => $ dom ->schemaTypeInfo ,
252
+ ];
253
+ }
254
+
199
255
return $ a ;
200
256
}
201
257
202
- public static function castText (\DOMText $ dom , array $ a , Stub $ stub , bool $ isNested ): array
258
+ public static function castText (\DOMText | \ DOM \ Text $ dom , array $ a , Stub $ stub , bool $ isNested ): array
203
259
{
204
260
$ a += [
205
261
'wholeText ' => $ dom ->wholeText ,
@@ -208,7 +264,7 @@ public static function castText(\DOMText $dom, array $a, Stub $stub, bool $isNes
208
264
return $ a ;
209
265
}
210
266
211
- public static function castDocumentType (\DOMDocumentType $ dom , array $ a , Stub $ stub , bool $ isNested ): array
267
+ public static function castDocumentType (\DOMDocumentType | \ DOM \ DocumentType $ dom , array $ a , Stub $ stub , bool $ isNested ): array
212
268
{
213
269
$ a += [
214
270
'name ' => $ dom ->name ,
@@ -222,7 +278,7 @@ public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $s
222
278
return $ a ;
223
279
}
224
280
225
- public static function castNotation (\DOMNotation $ dom , array $ a , Stub $ stub , bool $ isNested ): array
281
+ public static function castNotation (\DOMNotation | \ DOM \ Notation $ dom , array $ a , Stub $ stub , bool $ isNested ): array
226
282
{
227
283
$ a += [
228
284
'publicId ' => $ dom ->publicId ,
@@ -232,7 +288,7 @@ public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, boo
232
288
return $ a ;
233
289
}
234
290
235
- public static function castEntity (\DOMEntity $ dom , array $ a , Stub $ stub , bool $ isNested ): array
291
+ public static function castEntity (\DOMEntity | \ DOM \ Entity $ dom , array $ a , Stub $ stub , bool $ isNested ): array
236
292
{
237
293
$ a += [
238
294
'publicId ' => $ dom ->publicId ,
@@ -246,7 +302,7 @@ public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, bool $i
246
302
return $ a ;
247
303
}
248
304
249
- public static function castProcessingInstruction (\DOMProcessingInstruction $ dom , array $ a , Stub $ stub , bool $ isNested ): array
305
+ public static function castProcessingInstruction (\DOMProcessingInstruction | \ DOM \ ProcessingInstruction $ dom , array $ a , Stub $ stub , bool $ isNested ): array
250
306
{
251
307
$ a += [
252
308
'target ' => $ dom ->target ,
@@ -256,7 +312,7 @@ public static function castProcessingInstruction(\DOMProcessingInstruction $dom,
256
312
return $ a ;
257
313
}
258
314
259
- public static function castXPath (\DOMXPath $ dom , array $ a , Stub $ stub , bool $ isNested ): array
315
+ public static function castXPath (\DOMXPath | \ DOM \ XPath $ dom , array $ a , Stub $ stub , bool $ isNested ): array
260
316
{
261
317
$ a += [
262
318
'document ' => $ dom ->document ,
0 commit comments