From bfb5e6559fd6f80b017a4ad3bb725e070a9ce569 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 1 Jun 2015 23:04:08 +0200 Subject: [PATCH] (config) make legacy wrappers xml attribute aware --- .../mvc/app/library/OPNsense/Core/Config.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php index 41e6e4a89..a93554207 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php +++ b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php @@ -97,6 +97,14 @@ class Config extends Singleton $node = $this->simplexml; } + // copy attributes to @attribute key item + foreach ($node->attributes() as $AttrKey => $AttrValue) { + if (!array_key_exists('@attributes', $result)) { + $result['@attributes'] = array(); + } + $result['@attributes'][$AttrKey] = $AttrValue->__toString(); + } + // iterate xml children foreach ($node->children() as $xmlNode) { $xmlNodeName = $xmlNode->getName(); if ($xmlNode->count() > 0) { @@ -173,7 +181,13 @@ class Config extends Singleton ) { continue; } - if (is_numeric($itemKey)) { + if ($itemKey === '@attributes') { + // copy xml attributes + foreach ($itemValue as $attrKey => $attrValue) { + $node->addAttribute($attrKey, $attrValue); + } + continue; + } elseif (is_numeric($itemKey)) { // recurring tag (content), use parent tagname. $childNode = $node->addChild($parentTagName); } elseif (is_array($itemValue) && $this->isArraySequential($itemValue)) {