/** * Utilize custom serialization for XMLWriter object, to convert object * to SQL. * * @return string */ private function _serialize() { $this->setIndent(true); $this->setIndentString(' '); $this->startDocument('1.0', 'UTF-8'); $this->_namespaces = array(); $this->_tagStack = array(); $this->_state = array(); $this->_type = 'Tag'; $this->_expectedDepth = 0; $this->_lastkey = array(); $lastdepth = 0; foreach ($this->_iter = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->_array), \RecursiveIteratorIterator::SELF_FIRST) as $key => $values) { $depth = $this->_iter->getDepth(); while ($depth < $this->_expectedDepth) { // finished with this tag $this->_finish($key, $values); $lastdepth--; } if (isset($this->_lastkey[$depth]) && $key != $this->_lastkey[$depth]) { while ($lastdepth > $depth) { $this->_finish($key, $values); $lastdepth--; } } $this->_lastkey[$depth] = $key; foreach ($this->_lastkey as $d => &$k) { if ($d > $depth) { $k = false; } } $this->_lastkey = array_filter($this->_lastkey, array('Pyrus\\XMLWriter', '_filter')); $lastdepth = $depth; if ($this->_type !== 'Attribs') { if ($key === '_content') { $this->text($values); continue; } if ($key === 'attribs') { // attributes are 1 depth higher $this->_pushState(); $this->_expectedDepth = $this->_iter->getDepth() + 1; $this->_type = 'Attribs'; // cycle to first attribute continue; } } $next = '_handle' . $this->_type; while ($next = $this->{$next}($key, $values)) { } } while ($lastdepth) { $this->_finish($key, $values); $lastdepth--; } $this->endDocument(); return $this->flush(); }