@@ 251-273 (lines=23) @@ | ||
248 | } |
|
249 | } |
|
250 | ||
251 | public function mergeStructure(MergedStructure $base, \SimpleXMLElement $new) |
|
252 | { |
|
253 | $base->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration'); |
|
254 | foreach ($new as $item) { |
|
255 | if ($item instanceof \SimpleXMLElement) { |
|
256 | $xpath = sprintf('/*/s:section[@identifier="%s"]', $item['identifier']); |
|
257 | $sectionExists = $base->xpath($xpath); |
|
258 | ||
259 | if (!empty($sectionExists) && $sectionExists[0] instanceof \SimpleXMLElement) { |
|
260 | $section = $sectionExists[0]; |
|
261 | } else { |
|
262 | $section = $base->addChild('section'); |
|
263 | } |
|
264 | ||
265 | foreach ($item->attributes() as $name => $value) { |
|
266 | $section[$name] = (string)$value; |
|
267 | } |
|
268 | if ($item->group) { |
|
269 | $this->mergeGroup($section, $item->group); |
|
270 | } |
|
271 | } |
|
272 | } |
|
273 | } |
|
274 | ||
275 | protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups) |
|
276 | { |
|
@@ 275-294 (lines=20) @@ | ||
272 | } |
|
273 | } |
|
274 | ||
275 | protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $newGroups) |
|
276 | { |
|
277 | $section->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration'); |
|
278 | foreach ($newGroups as $newGroup) { |
|
279 | if ($newGroup instanceof \SimpleXMLElement) { |
|
280 | $xpath = sprintf('./s:group[@identifier="%s"]', $newGroup['identifier']); |
|
281 | $groupExists = $section->xpath($xpath); |
|
282 | ||
283 | if (!empty($groupExists) && $groupExists[0] instanceof \SimpleXMLElement) { |
|
284 | $group = $groupExists[0]; |
|
285 | } else { |
|
286 | $group = $section->addChild('group'); |
|
287 | } |
|
288 | foreach ($newGroup->attributes() as $name => $value) { |
|
289 | $group[$name] = (string)$value; |
|
290 | } |
|
291 | $this->mergeElements($group, $newGroup->element); |
|
292 | } |
|
293 | } |
|
294 | } |
|
295 | ||
296 | protected function mergeElements(\SimpleXMLElement $group, \SimpleXMLElement $newElements) |
|
297 | { |
|
@@ 296-315 (lines=20) @@ | ||
293 | } |
|
294 | } |
|
295 | ||
296 | protected function mergeElements(\SimpleXMLElement $group, \SimpleXMLElement $newElements) |
|
297 | { |
|
298 | $group->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration'); |
|
299 | foreach ($newElements as $newElement) { |
|
300 | if ($newElement instanceof \SimpleXMLElement) { |
|
301 | $xpath = sprintf('./s:element[@identifier="%s"]', $newElement['identifier']); |
|
302 | $elementExists = $group->xpath($xpath); |
|
303 | ||
304 | if (!empty($elementExists) && $elementExists[0] instanceof \SimpleXMLElement) { |
|
305 | $element = $elementExists[0]; |
|
306 | } else { |
|
307 | $element = $group->addChild('element'); |
|
308 | } |
|
309 | foreach ($newElement->attributes() as $name => $value) { |
|
310 | $element[$name] = (string)$value; |
|
311 | } |
|
312 | $this->mergeAllChildren($element, $newElement); |
|
313 | } |
|
314 | } |
|
315 | } |
|
316 | ||
317 | protected function mergeAllChildren(\SimpleXMLElement $destination, \SimpleXMLElement $source) |
|
318 | { |