RomaricDrigon\MetaYaml\Loader\XmlLoader::xmlToArray PHP Method

xmlToArray() private method

* Private XML parser
private xmlToArray ( SimpleXMLIterator $sxi )
$sxi SimpleXMLIterator
    private function xmlToArray(\SimpleXMLIterator $sxi)
    {
        $a = array();
        for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
            $t = array();
            $current = $sxi->current();
            $attributes = $current->attributes();
            $name = isset($attributes->_key) ? strval($attributes->_key) : $sxi->key();
            // save attributes
            foreach ($attributes as $att_key => $att_value) {
                if ($att_key !== '_key') {
                    $t[$att_key] = strval($att_value);
                }
            }
            // we parse nodes
            if ($sxi->hasChildren()) {
                // children
                $t = array_merge($t, $this->xmlToArray($current));
            } else {
                // it's a leaf
                if (empty($t)) {
                    $t = strval($current);
                    // strval will call _toString()
                } else {
                    $t['_value'] = strval($current);
                    // strval will call _toString()
                }
            }
            $a[$name] = $t;
        }
        return $a;
    }