Exemplo n.º 1
0
 /**
  * Parse properties recursively
  *
  * @param \SimpleXML $xml XML object to parse
  *
  * @return array
  */
 private function _fromXmlToArray($xml)
 {
     $result = array();
     $dataNamespace = Resources::DS_XML_NAMESPACE;
     foreach ($xml->children($dataNamespace) as $child) {
         if (count($child->children($dataNamespace)) > 0) {
             $value = array();
             foreach ($child->children($dataNamespace) as $subChild) {
                 if ($subChild->getName() == 'element') {
                     $value[] = $this->_fromXmlToArray($subChild);
                 }
             }
         } else {
             $value = (string) $child;
         }
         $result[$child->getName()] = $value;
     }
     return $result;
 }
 /**
  * Parse properties recursively
  *
  * @param \SimpleXML $xml XML object to parse
  *
  * @return array
  */
 private static function _unserializeRecursive($xml)
 {
     $result = array();
     $dataNamespace = Resources::DS_XML_NAMESPACE;
     foreach ($xml->children($dataNamespace) as $child) {
         if (count($child->children($dataNamespace)) > 0) {
             $value = array();
             $children = $child->children($dataNamespace);
             $firstChild = $children[0];
             if ($firstChild->getName() == 'element') {
                 foreach ($children as $subChild) {
                     $value[] = ContentPropertiesSerializer::_unserializeRecursive($subChild);
                 }
             } else {
                 $value = ContentPropertiesSerializer::_unserializeRecursive($child);
             }
         } else {
             $value = (string) $child;
         }
         $result[$child->getName()] = $value;
     }
     return $result;
 }
 /**
  * SimpleXML helper, append 2 objects together
  * @param SimpleXML $to
  * @param SimpleXML $from
  */
 protected function _append(&$to, $from)
 {
     // go through each kid
     foreach ($from->children() as $child) {
         $temp = $to->addChild($child->getName(), (string) $child);
         foreach ($child->attributes() as $key => $value) {
             $temp->addAttribute($key, $value);
         }
         // perform append
         $this->_append($temp, $child);
     }
 }