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