Beispiel #1
0
 /**
  * Convert a DOMNode into a CFType.
  * @param DOMNode $node Node to import children of
  * @param CFDictionary|CFArray|CFPropertyList $parent 
  * @return void
  */
 protected function import(DOMNode $node, $parent)
 {
     // abort if there are no children
     if (!$node->childNodes->length) {
         return;
     }
     foreach ($node->childNodes as $n) {
         // skip if we can't handle the element
         if (!isset(self::$types[$n->nodeName])) {
             continue;
         }
         $class = self::$types[$n->nodeName];
         $key = null;
         // find previous <key> if possible
         $ps = $n->previousSibling;
         while ($ps && $ps->nodeName == '#text' && $ps->previousSibling) {
             $ps = $ps->previousSibling;
         }
         // read <key> if possible
         if ($ps && $ps->nodeName == 'key') {
             $key = $ps->firstChild->nodeValue;
         }
         switch ($n->nodeName) {
             case 'date':
                 $value = new $class(CFDate::dateValue($n->nodeValue));
                 break;
             case 'data':
                 $value = new $class($n->nodeValue, true);
                 break;
             case 'string':
                 $value = new $class($n->nodeValue);
                 break;
             case 'real':
             case 'integer':
                 $value = new $class($n->nodeName == 'real' ? floatval($n->nodeValue) : intval($n->nodeValue));
                 break;
             case 'true':
             case 'false':
                 $value = new $class($n->nodeName == 'true');
                 break;
             case 'array':
             case 'dict':
                 $value = new $class();
                 $this->import($n, $value);
                 break;
         }
         // Dictionaries need a key
         if ($parent instanceof CFDictionary) {
             $parent->add($key, $value);
         } else {
             $parent->add($value);
         }
     }
 }
Beispiel #2
0
 protected function import(DOMNode $node, $parent)
 {
     if (!$node->childNodes->length) {
         return;
     }
     foreach ($node->childNodes as $n) {
         if (!isset(self::$types[$n->nodeName])) {
             continue;
         }
         $class = self::$types[$n->nodeName];
         $key = null;
         $ps = $n->previousSibling;
         while ($ps && $ps->nodeName == '#text' && $ps->previousSibling) {
             $ps = $ps->previousSibling;
         }
         if ($ps && $ps->nodeName == 'key') {
             $key = $ps->firstChild->nodeValue;
         }
         switch ($n->nodeName) {
             case 'date':
                 $value = new $class(CFDate::dateValue($n->nodeValue));
                 break;
             case 'data':
                 $value = new $class($n->nodeValue, true);
                 break;
             case 'string':
                 $value = new $class($n->nodeValue);
                 break;
             case 'real':
             case 'integer':
                 $value = new $class($n->nodeName == 'real' ? floatval($n->nodeValue) : intval($n->nodeValue));
                 break;
             case 'true':
             case 'false':
                 $value = new $class($n->nodeName == 'true');
                 break;
             case 'array':
             case 'dict':
                 $value = new $class();
                 $this->import($n, $value);
                 break;
         }
         if ($parent instanceof CFDictionary) {
             $parent->add($key, $value);
         } else {
             $parent->add($value);
         }
     }
 }