src/CFPropertyList/CFPropertyList.php
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 = __NAMESPACE__ . '\\'.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);

                    if ($value instanceof CFDictionary) {
                        $hsh = $value->getValue();
                        if (isset($hsh['CF$UID']) && count($hsh) == 1) {
                            $value = new CFUid($hsh['CF$UID']->getValue());
                        }
                    }

                    break;
            }

        // Dictionaries need a key
            if ($parent instanceof CFDictionary) {
                $parent->add($key, $value);
            } // others don't
            else {
                $parent->add($value);
            }
        }
    }
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 = __NAMESPACE__ . '\\'.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);

                    if ($value instanceof CFDictionary) {
                        $hsh = $value->getValue();
                        if (isset($hsh['CF$UID']) && count($hsh) == 1) {
                            $value = new CFUid($hsh['CF$UID']->getValue());
                        }
                    }

                    break;
            }

        // Dictionaries need a key
            if ($parent instanceof CFDictionary) {
                $parent->add($key, $value);
            } // others don't
            else {
                $parent->add($value);
            }
        }
    }
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 = __NAMESPACE__ . '\\' . 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 ) ; if ( $ value instanceof CFDictionary ) { $ hsh = $ value -> getValue ( ) ; if ( isset ( $ hsh [ 'CF$UID' ] ) && count ( $ hsh ) == 1 ) { $ value = new CFUid ( $ hsh [ 'CF$UID' ] -> getValue ( ) ) ; } } break ; } // Dictionaries need a key if ( $ parent instanceof CFDictionary ) { $ parent -> add ( $ key , $ value ) ; } // others don't else { $ parent -> add ( $ value ) ; } } }
Convert a DOMNode into a CFType.
@param DOMNode $node Node to import children of
@param CFDictionary|CFArray|CFPropertyList $parent
@return void
Convert a DOMNode into a CFType .