@@ -114,10 +114,10 @@ public function decode($data, $format, array $context = array())
114
114
unset($ data ['@xmlns:xml ' ]);
115
115
116
116
if (empty ($ data )) {
117
- return $ this ->parseXml ($ rootNode );
117
+ return $ this ->parseXml ($ rootNode, $ context );
118
118
}
119
119
120
- return array_merge ($ data , (array ) $ this ->parseXml ($ rootNode ));
120
+ return array_merge ($ data , (array ) $ this ->parseXml ($ rootNode, $ context ));
121
121
}
122
122
123
123
if (!$ rootNode ->hasAttributes ()) {
@@ -256,11 +256,11 @@ final protected function isElementNameValid($name)
256
256
*
257
257
* @return array|string
258
258
*/
259
- private function parseXml (\DOMNode $ node )
259
+ private function parseXml (\DOMNode $ node, array $ context = array () )
260
260
{
261
- $ data = $ this ->parseXmlAttributes ($ node );
261
+ $ data = $ this ->parseXmlAttributes ($ node, $ context );
262
262
263
- $ value = $ this ->parseXmlValue ($ node );
263
+ $ value = $ this ->parseXmlValue ($ node, $ context );
264
264
265
265
if (!count ($ data )) {
266
266
return $ value ;
@@ -292,16 +292,17 @@ private function parseXml(\DOMNode $node)
292
292
*
293
293
* @return array
294
294
*/
295
- private function parseXmlAttributes (\DOMNode $ node )
295
+ private function parseXmlAttributes (\DOMNode $ node, array $ context = array () )
296
296
{
297
297
if (!$ node ->hasAttributes ()) {
298
298
return array ();
299
299
}
300
300
301
301
$ data = array ();
302
+ $ typeCastAttributes = $ this ->resolveXmlTypeCastAttributes ($ context );
302
303
303
304
foreach ($ node ->attributes as $ attr ) {
304
- if (!is_numeric ($ attr ->nodeValue )) {
305
+ if (!is_numeric ($ attr ->nodeValue ) || ! $ typeCastAttributes ) {
305
306
$ data ['@ ' .$ attr ->nodeName ] = $ attr ->nodeValue ;
306
307
307
308
continue ;
@@ -326,7 +327,7 @@ private function parseXmlAttributes(\DOMNode $node)
326
327
*
327
328
* @return array|string
328
329
*/
329
- private function parseXmlValue (\DOMNode $ node )
330
+ private function parseXmlValue (\DOMNode $ node, array $ context = array () )
330
331
{
331
332
if (!$ node ->hasChildNodes ()) {
332
333
return $ node ->nodeValue ;
@@ -343,7 +344,7 @@ private function parseXmlValue(\DOMNode $node)
343
344
continue ;
344
345
}
345
346
346
- $ val = $ this ->parseXml ($ subnode );
347
+ $ val = $ this ->parseXml ($ subnode, $ context );
347
348
348
349
if ('item ' === $ subnode ->nodeName && isset ($ val ['@key ' ])) {
349
350
if (isset ($ val ['# ' ])) {
@@ -522,6 +523,20 @@ private function resolveXmlRootName(array $context = array())
522
523
: $ this ->rootNodeName ;
523
524
}
524
525
526
+ /**
527
+ * Get XML option for type casting attributes Defaults to true.
528
+ *
529
+ * @param array $context
530
+ *
531
+ * @return bool
532
+ */
533
+ private function resolveXmlTypeCastAttributes (array $ context = array ())
534
+ {
535
+ return isset ($ context ['xml_type_cast_attributes ' ])
536
+ ? (bool ) $ context ['xml_type_cast_attributes ' ]
537
+ : true ;
538
+ }
539
+
525
540
/**
526
541
* Create a DOM document, taking serializer options into account.
527
542
*
0 commit comments