Exemplo n.º 1
0
 /**
  * Merge 2 xml element (were convert to array)
  *
  * @param array &$element1   Element data
  * @param arrar &$element2   Element data
  *
  * @return array Merged element
  */
 function merge_xml(&$element1, &$element2)
 {
     for ($i = 0, $n = count($element1->_children); $i < $n; $i++) {
         $child1 = $element1->_children[$i];
         $name = $child1->name();
         if ($name == 'blocks') {
             $child2 = T3Common::xml_find_element($element2, 'blocks', 'name', $child1->attributes('name'));
             if (!$child2) {
                 //Add child1 into element2
                 $element2->{$name}[] = $child1;
                 //Add the reference to the children array member
                 $element2->_children[] = $child1;
             }
         } else {
             $child2 = null;
             if ($child1->attributes('name')) {
                 $child2 = T3Common::xml_find_element($element2, $name, 'name', $child1->attributes('name'));
             } else {
                 $child2 = T3Common::xml_find_element($element2, $name);
             }
             if (!isset($child1->_children) || !count($child1->_children) || !$child2) {
                 //$element2->{$name} = array();
                 //Add child1 into element2
                 $element2->{$name}[] = $child1;
                 //Add the reference to the children array member
                 $element2->_children[] = $child1;
             } else {
                 $element2->{$name}[isset($child2->_index) ? $child2->_index : 0] = T3Common::merge_xml($child1, $child2);
             }
         }
     }
     return $element2;
 }