@@ 246-268 (lines=23) @@ | ||
243 | } |
|
244 | } |
|
245 | ||
246 | public function mergeStructure(MergedStructure $base, \SimpleXMLElement $new) |
|
247 | { |
|
248 | $base->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration'); |
|
249 | foreach ($new as $item) { |
|
250 | if ($item instanceof \SimpleXMLElement) { |
|
251 | $xpath = sprintf('/*/s:section[@identifier="%s"]', $item['identifier']); |
|
252 | $sectionExists = $base->xpath($xpath); |
|
253 | ||
254 | if (!empty($sectionExists) && $sectionExists[0] instanceof \SimpleXMLElement) { |
|
255 | $section = $sectionExists[0]; |
|
256 | } else { |
|
257 | $section = $base->addChild('section'); |
|
258 | } |
|
259 | ||
260 | foreach ($item->attributes() as $name => $value) { |
|
261 | $section[$name] = (string)$value; |
|
262 | } |
|
263 | if ($item->group) { |
|
264 | $this->mergeGroup($section, $item->group); |
|
265 | } |
|
266 | } |
|
267 | } |
|
268 | } |
|
269 | ||
270 | protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups) |
|
271 | { |
|
@@ 270-289 (lines=20) @@ | ||
267 | } |
|
268 | } |
|
269 | ||
270 | protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups) |
|
271 | { |
|
272 | $section->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration'); |
|
273 | foreach ($newGroups as $newGroup) { |
|
274 | if ($newGroup instanceof \SimpleXMLElement) { |
|
275 | $xpath = sprintf('./s:group[@identifier="%s"]', $newGroup['identifier']); |
|
276 | $groupExists = $section->xpath($xpath); |
|
277 | ||
278 | if (!empty($groupExists) && $groupExists[0] instanceof \SimpleXMLElement) { |
|
279 | $group = $groupExists[0]; |
|
280 | } else { |
|
281 | $group = $section->addChild('group'); |
|
282 | } |
|
283 | foreach ($newGroup->attributes() as $name => $value) { |
|
284 | $group[$name] = (string)$value; |
|
285 | } |
|
286 | $this->mergeElements($group, $newGroup->element); |
|
287 | } |
|
288 | } |
|
289 | } |
|
290 | ||
291 | protected function mergeElements(\SimpleXMLElement $group, \SimpleXMLElement $newElements) |
|
292 | { |