@@ -119,10 +119,10 @@ public function decode($data, $format, array $context = array())
119
119
unset($ data ['@xmlns:xml ' ]);
120
120
121
121
if (empty ($ data )) {
122
- return $ this ->parseXml ($ rootNode );
122
+ return $ this ->parseXml ($ rootNode, $ context );
123
123
}
124
124
125
- return array_merge ($ data , (array ) $ this ->parseXml ($ rootNode ));
125
+ return array_merge ($ data , (array ) $ this ->parseXml ($ rootNode, $ context ));
126
126
}
127
127
128
128
if (!$ rootNode ->hasAttributes ()) {
@@ -261,11 +261,11 @@ final protected function isElementNameValid($name)
261
261
*
262
262
* @return array|string
263
263
*/
264
- private function parseXml (\DOMNode $ node )
264
+ private function parseXml (\DOMNode $ node, array $ context = array () )
265
265
{
266
- $ data = $ this ->parseXmlAttributes ($ node );
266
+ $ data = $ this ->parseXmlAttributes ($ node, $ context );
267
267
268
- $ value = $ this ->parseXmlValue ($ node );
268
+ $ value = $ this ->parseXmlValue ($ node, $ context );
269
269
270
270
if (!count ($ data )) {
271
271
return $ value ;
@@ -297,16 +297,17 @@ private function parseXml(\DOMNode $node)
297
297
*
298
298
* @return array
299
299
*/
300
- private function parseXmlAttributes (\DOMNode $ node )
300
+ private function parseXmlAttributes (\DOMNode $ node, array $ context = array () )
301
301
{
302
302
if (!$ node ->hasAttributes ()) {
303
303
return array ();
304
304
}
305
305
306
306
$ data = array ();
307
+ $ typeCastAttributes = $ this ->resolveXmlTypeCastAttributes ($ context );
307
308
308
309
foreach ($ node ->attributes as $ attr ) {
309
- if (!is_numeric ($ attr ->nodeValue )) {
310
+ if (!is_numeric ($ attr ->nodeValue ) || ! $ typeCastAttributes ) {
310
311
$ data ['@ ' .$ attr ->nodeName ] = $ attr ->nodeValue ;
311
312
312
313
continue ;
@@ -331,7 +332,7 @@ private function parseXmlAttributes(\DOMNode $node)
331
332
*
332
333
* @return array|string
333
334
*/
334
- private function parseXmlValue (\DOMNode $ node )
335
+ private function parseXmlValue (\DOMNode $ node, array $ context = array () )
335
336
{
336
337
if (!$ node ->hasChildNodes ()) {
337
338
return $ node ->nodeValue ;
@@ -348,7 +349,7 @@ private function parseXmlValue(\DOMNode $node)
348
349
continue ;
349
350
}
350
351
351
- $ val = $ this ->parseXml ($ subnode );
352
+ $ val = $ this ->parseXml ($ subnode, $ context );
352
353
353
354
if ('item ' === $ subnode ->nodeName && isset ($ val ['@key ' ])) {
354
355
if (isset ($ val ['# ' ])) {
@@ -527,6 +528,20 @@ private function resolveXmlRootName(array $context = array())
527
528
: $ this ->rootNodeName ;
528
529
}
529
530
531
+ /**
532
+ * Get XML option for type casting attributes Defaults to true.
533
+ *
534
+ * @param array $context
535
+ *
536
+ * @return bool
537
+ */
538
+ private function resolveXmlTypeCastAttributes (array $ context = array ())
539
+ {
540
+ return isset ($ context ['xml_type_cast_attributes ' ])
541
+ ? (bool ) $ context ['xml_type_cast_attributes ' ]
542
+ : true ;
543
+ }
544
+
530
545
/**
531
546
* Create a DOM document, taking serializer options into account.
532
547
*
0 commit comments