@@ -52,6 +52,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
52
52
const ROOT_NODE_NAME = 'xml_root_node_name ' ;
53
53
const STANDALONE = 'xml_standalone ' ;
54
54
const TYPE_CAST_ATTRIBUTES = 'xml_type_cast_attributes ' ;
55
+ const TYPE_CAST_NODES = 'xml_type_cast_nodes ' ;
55
56
const VERSION = 'xml_version ' ;
56
57
57
58
private $ defaultContext = [
@@ -62,6 +63,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
62
63
self ::REMOVE_EMPTY_TAGS => false ,
63
64
self ::ROOT_NODE_NAME => 'response ' ,
64
65
self ::TYPE_CAST_ATTRIBUTES => true ,
66
+ self ::TYPE_CAST_NODES => true ,
65
67
];
66
68
67
69
/**
@@ -325,16 +327,18 @@ private function parseXmlValue(\DOMNode $node, array $context = [])
325
327
return $ node ->nodeValue ;
326
328
}
327
329
330
+ $ typeCastNodes = (bool ) ($ context [self ::TYPE_CAST_NODES ] ?? $ this ->defaultContext [self ::TYPE_CAST_NODES ]);
331
+
328
332
if (1 === $ node ->childNodes ->length && \in_array ($ node ->firstChild ->nodeType , [XML_TEXT_NODE , XML_CDATA_SECTION_NODE ])) {
329
- if (false !== $ val = filter_var ($ node ->firstChild ->nodeValue , FILTER_VALIDATE_INT ) ) {
330
- return $ val ;
333
+ if (! is_numeric ($ node ->firstChild ->nodeValue ) || ! $ typeCastNodes ) {
334
+ return $ node -> firstChild -> nodeValue ;
331
335
}
332
336
333
- if (false !== $ val = filter_var ($ node ->firstChild ->nodeValue , FILTER_VALIDATE_FLOAT )) {
337
+ if (false !== $ val = filter_var ($ node ->firstChild ->nodeValue , FILTER_VALIDATE_INT )) {
334
338
return $ val ;
335
339
}
336
340
337
- return $ node ->firstChild ->nodeValue ;
341
+ return ( float ) $ node ->firstChild ->nodeValue ;
338
342
}
339
343
340
344
$ value = [];
0 commit comments