| @@ 171-193 (lines=23) @@ | ||
| 168 | } |
|
| 169 | } |
|
| 170 | ||
| 171 | public function mergeStructure(\SimpleXMLElement $base, \SimpleXMLElement $new) |
|
| 172 | { |
|
| 173 | $base->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration'); |
|
| 174 | foreach ($new as $item) { |
|
| 175 | if ($item instanceof \SimpleXMLElement) { |
|
| 176 | $xpath = sprintf('/*/s:section[@id="%s"]', $item['id']); |
|
| 177 | $sectionExists = $base->xpath($xpath); |
|
| 178 | ||
| 179 | if (!empty($sectionExists) && $sectionExists[0] instanceof \SimpleXMLElement) { |
|
| 180 | $section = $sectionExists[0]; |
|
| 181 | } else { |
|
| 182 | $section = $base->addChild('section'); |
|
| 183 | } |
|
| 184 | ||
| 185 | foreach ($item->attributes() as $name => $value) { |
|
| 186 | $section[$name] = $value; |
|
| 187 | } |
|
| 188 | if ($item->group) { |
|
| 189 | $this->mergeGroup($section, $item->group); |
|
| 190 | } |
|
| 191 | } |
|
| 192 | } |
|
| 193 | } |
|
| 194 | ||
| 195 | protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups) |
|
| 196 | { |
|
| @@ 195-214 (lines=20) @@ | ||
| 192 | } |
|
| 193 | } |
|
| 194 | ||
| 195 | protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups) |
|
| 196 | { |
|
| 197 | $section->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration'); |
|
| 198 | foreach ($newGroups as $newGroup) { |
|
| 199 | if ($newGroup instanceof \SimpleXMLElement) { |
|
| 200 | $xpath = sprintf('./s:group[@id="%s"]', $newGroup['id']); |
|
| 201 | $groupExists = $section->xpath($xpath); |
|
| 202 | ||
| 203 | if (!empty($groupExists) && $groupExists[0] instanceof \SimpleXMLElement) { |
|
| 204 | $group = $groupExists[0]; |
|
| 205 | } else { |
|
| 206 | $group = $section->addChild('group'); |
|
| 207 | } |
|
| 208 | foreach ($newGroup->attributes() as $name => $value) { |
|
| 209 | $group[$name] = $value; |
|
| 210 | } |
|
| 211 | $this->mergeElements($group, $newGroup->element); |
|
| 212 | } |
|
| 213 | } |
|
| 214 | } |
|
| 215 | ||
| 216 | protected function mergeElements(\SimpleXMLElement $group, \SimpleXMLElement $newElements) |
|
| 217 | { |
|