Пример #1
0
 /**
  * @param XML $xml
  * @param array $data
  * @return void
  * @SuppressWarnings(PHPMD.ElseExpression)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function appendDataXml(XML &$xml, array &$data)
 {
     foreach ($data as $key => &$value) {
         $child = new XML();
         $child->setName($key);
         $child->setCData(true);
         $child->setRoot(false);
         $type = gettype($value);
         $child->setAttribute('type', $type);
         switch ($type) {
             case 'boolean':
                 $child->setValue((int) $value);
                 break;
             case 'integer':
                 $child->setValue((int) $value);
                 break;
             case 'double':
             case 'float':
                 $child->setValue((double) $value);
                 break;
             case 'string':
                 $child->setValue((string) $value);
                 break;
             case 'array':
                 $this->appendDataXml($child, $value);
                 break;
             case 'object':
                 $child->setAttribute('class', get_class($value));
                 if ($value instanceof self) {
                     $array = $value->getArray();
                     $this->appendDataXml($child, $array);
                 } else {
                     $serialize = serialize($value);
                     $child->setValue($serialize);
                 }
                 break;
             case 'resource':
             case 'null':
             case 'unknown type':
             default:
                 $child->setValue('null');
                 break;
         }
         $xml->appendChild($child);
     }
 }