Example #1
0
 /**
  * Unserialization handler; handles $this->_element being an instance of
  * DOMElement or Horde_Xml_Element, or parses it as an XML string.
  */
 public function __wakeup()
 {
     if ($this->_element instanceof DOMElement) {
         return true;
     }
     if ($this->_element instanceof Horde_Xml_Element) {
         $this->_element = $this->_element->getDom();
         return true;
     }
     if ($this->_serialized) {
         $this->_element = $this->_serialized;
         $this->_serialized = null;
     }
     if (is_string($this->_element)) {
         $doc = new DOMDocument();
         $doc->preserveWhiteSpace = false;
         $extract = false;
         if (substr($this->_element, 0, 5) != '<?xml') {
             $extract = true;
             $preamble = '<?xml version="1.0" encoding="UTF-8" ?><root ';
             foreach (self::$_namespaces as $prefix => $nsUri) {
                 $preamble .= " xmlns:{$prefix}=\"{$nsUri}\"";
             }
             $preamble .= '>';
             $this->_element = $preamble . $this->_element . '</root>';
         }
         $loaded = @$doc->loadXML($this->_element);
         if (!$loaded) {
             throw new Horde_Xml_Element_Exception('DOMDocument cannot parse XML: ', error_get_last());
         }
         if ($extract) {
             $newDoc = new DOMDocument();
             $this->_element = $newDoc->importNode($doc->documentElement->childNodes->item(0), true);
         } else {
             $this->_element = $doc->documentElement;
         }
         return true;
     }
     throw new InvalidArgumentException('Horde_Xml_Element initialization value must be a DOMElement, a Horde_Xml_Element, or a non-empty string; ' . (gettype($this->_element) == 'object' ? get_class($this->_element) : gettype($this->_element)) . ' given');
 }