Initialize from a simple XML object

@param \SimpleXMLElement $xmlObject
@throws \Exception
435733
private function initializeFromSimpleXML($xmlObject)
    {
        $this->path = !empty($xmlObject->path) ? trim($xmlObject->path) : '/';
        $this->name = !empty($xmlObject->name) ? trim($xmlObject->name) : '';
        $this->class = !empty($xmlObject->class) ? trim($xmlObject->class) : '';

        $this->priority = !empty($xmlObject->priority) ? intval($xmlObject->priority) : 0;

        $this->patternString = !empty($xmlObject->pattern) ? (string)$xmlObject->pattern : null;
        $this->pattern = !empty($this->patternString) ? new Pattern($this->path, $this->patternString) : null;

        $this->parameters = new \stdClass();

        //Build route parameters into an object because SimpleXMLElements can't be memcached
        if (!empty($xmlObject->parameters) && $xmlObject->parameters->children()) {
            foreach ($xmlObject->parameters->children() as $parameter) {
                $parameterName = (string)$parameter->getName();
                $parameterValue = (string)$parameter;
                $parameterAttributes = [];

                $attributes = $parameter->attributes();
                foreach ($attributes as $attributeName => $attributeValue) {
                    $parameterAttributes[(string)$attributeName] = (string)$attributeValue;
                }

                $parameterObject = new \Slab\Router\Parameter($parameterName, $parameterValue, $parameterAttributes);

                if (!empty($this->parameters->$parameterName)) {
                    if (is_array($this->parameters->$parameterName)) {
                        $this->parameters->{$parameterName}[] = $parameterObject;
                    } else {
                        $this->parameters->$parameterName = array($this->parameters->$parameterName, $parameterObject);
                    }
                } else {
                    $this->parameters->$parameterName = $parameterObject;
                }
            }
        }
    }
21115
final XML newXMLFromJs(Object inputObject) {
        String frag;

        if (inputObject == null || inputObject == Undefined.instance) {
            frag = "";
        } else if (inputObject instanceof XMLObjectImpl) {
            // todo: faster way for XMLObjects?
            frag = ((XMLObjectImpl) inputObject).toXMLString();
        } else {
            frag = ScriptRuntime.toString(inputObject);
        }

        if (frag.trim().startsWith("<>")) {
            throw ScriptRuntime.typeError("Invalid use of XML object anonymous tags <></>.");
        }

        if (frag.indexOf("<") == -1) {
            //    Solo text node
            return newXML(XmlNode.createText(options, frag));
        }
        return parse(frag);
    }
552806
public static function &createArray($input_xml) {
        $xml = self::getXMLRoot();
        if(is_string($input_xml)) {
            $parsed = $xml->loadXML($input_xml);
            if(!$parsed) {
                throw new \Exception('[XML2Array] Error parsing the XML string.');
            }
        } else {
            if(get_class($input_xml) != 'DOMDocument') {
                throw new \Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
            }
            $xml = self::$xml = $input_xml;
        }
        $array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
        self::$xml = null;    // clear the xml node in the class for 2nd time use.
        return $array;
    }
853569
function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
    {
        if ( $currentVersion != false )
        {
            $dataText = $originalContentObjectAttribute->content();
            $contentObjectAttribute->setContent( $dataText );
        }
        else
        {
            $default = array( 'value' => array() );
            $contentObjectAttribute->setContent( $default );
        }
    }
361925
public function writeXml(\XMLWriter $xmlWriter)
    {
        $content = null;
        if (!is_null($this->_subscriptionDescription)) {
            $content = new Content();
            $content->setText(
                XmlSerializer::objectSerialize(
                    $this->_subscriptionDescription,
                    'SubscriptionDescription'
                )
            );
        }
        $this->_entry->setContent($content);
        $this->_entry->writeXml($xmlWriter);
    }
728398
protected function loadXMLString($xmlString)
    {
        $document = new DOMDocument();

        libxml_use_internal_errors(true);
        libxml_clear_errors();

        // Options:
        // - substitute entities
        // - disable network access
        // - relax parser limits for document size/complexity
        $success = $document->loadXML($xmlString, LIBXML_NOENT | LIBXML_NONET | LIBXML_PARSEHUGE);

        if (!$success) {
            $messages = array();

            foreach (libxml_get_errors() as $error) {
                $messages[] = trim($error->message);
            }

            throw new InvalidArgumentException(
                '$inputValue',
                'Could not create XML document: ' . implode("\n", $messages)
            );
        }

        return $document;
    }
606404
public static function fromXML($xml)
    {
        $dom = new DOMDocument();
        $dom->loadXML($xml);
        $xpath = new DOMXPath($dom);
        $xpath->registerNamespace('a', self::getNamespace());
        $response = $xpath->query('//a:CaptureNotification');
        if ($response->length == 1) {
            return 
                new OffAmazonPaymentsNotifications_Model_CaptureNotification(
                    $response->item(0)
                );
        } else {
            throw new Exception(
                "Unable to construct " .
                "OffAmazonPaymentsNotifications_Model_CaptureNotification" .
                "from provided XML. Make sure that CaptureNotification" .
                "is a root element"
            );
        }
    }
368864
public function collect(SimpleXMLElement $element)
    {
        if ($element->getName() === get_called_class()::getTagName() && $this->locateDataObject($element)) {
            $this->getAttributes($element);
            $this->getChilds($element);
        } else {
            throw new ENabuXMLException(ENabuXMLException::ERROR_UNEXPECTED_ELEMENT, array($element->getName()));
        }
    }
446349
public function fromXml(SimpleXMLElement $xmlElement)
    {
        $classname = $this->xmlElementToClassname($xmlElement);
        if (!is_null($classname)) {
            $return = new $classname();
            if ($return instanceof ArrayObject) {
                foreach ($xmlElement as $xmlChild) {
                    $return->append($this->fromXml($xmlChild));
                }
            } else {
                $objectData = array();
                foreach ($xmlElement as $xmlChild) {
                    $key = $this->xmlkeyToProperty($xmlChild->getName());
                    if (isset($objectData[$key])) {
                        if (!is_array($objectData[$key])) {
                            $objectData[$key] = array($objectData[$key]);
                        }
                        $objectData[$key][] = $this->fromXml($xmlChild);
                    } else {
                        $objectData[$key] = $this->fromXml($xmlChild);
                    }
                }
                $return->setData($objectData, false);
            }
        } else {
            $return = $this->castValue($xmlElement);
        }

        return $return;
    }
664516
public function setContentObject($contentObject)
    {
        if (!is_object($contentObject)) {
            throw new \InvalidArgumentException('Argument must be an object, ' . \gettype($contentObject) . ' given.', 1283522467);
        }
        if ($this->contentObjectProxy === null || $this->contentObjectProxy->getObject() !== $contentObject) {
            $this->contentObjectProxy = new ContentObjectProxy($contentObject);
            $this->addOrUpdate();
        }
    }
181321
public static function fromDomainObject($domainObject)
    {
        if (!is_object($domainObject)) {
            throw new InvalidDomainObjectException('$domainObject must be an object.');
        }

        try {
            if ($domainObject instanceof HierarchicalDomainObjectInterface) {
                return new self(
                    $domainObject->getHierarchicalObjectIdentifiers(),
                    $domainObject->getObjectIdentifier(),
                    ClassUtils::getRealClass($domainObject)
                );
            }

            return parent::fromDomainObject($domainObject);
        } catch (\InvalidArgumentException $invalid) {
            throw new InvalidDomainObjectException($invalid->getMessage(), 0, $invalid);
        }

        throw new InvalidDomainObjectException('$domainObject must either implement the HierarchicalDomainObjectInterface, DomainObjectInterface, or have a method named "getId".');
    }
74353
function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
    {

        if ( $currentVersion != false )
        {
            $matrix = $originalContentObjectAttribute->content();
            $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
            // make sure that $matrix contains right columns
            $matrix->adjustColumnsToDefinition( $contentClassAttribute->attribute( 'content' ) );

            $contentObjectAttribute->setAttribute( 'data_text', $matrix->xmlString() );
            $contentObjectAttribute->setContent( $matrix );
        }
        else
        {
            $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
            $numRows = $contentClassAttribute->attribute( 'data_int1' );
            $matrix = new eZMatrix( '', $numRows, $contentClassAttribute->attribute( 'content' ) );
            // 'default name' is never used => just a stub
            // $matrix->setName( $contentClassAttribute->attribute( 'data_text1' ) );
            $contentObjectAttribute->setAttribute( 'data_text', $matrix->xmlString() );
            $contentObjectAttribute->setContent( $matrix );
        }

    }
1351702
public static function Init($xml)
    {
        $obj = new self();
        $obj->FromXml($xml);
        //fix bug 2015-06-29
        if($obj->values['return_code'] != 'SUCCESS'){
            return $obj->GetValues();
        }
        $obj->CheckSign();
        return $obj->GetValues();
    }
319338
protected function logBadXML($xml)
    {
        $file = @fopen($this->badXmlLog, 'a');
        if (!$file) {
            throw new \Exception("Problem opening {$this->badXmlLog}.");
        }
        fputs($file, $xml . "\n\n");
        fclose($file);
    }
647641
public function pcmlToArray(\SimpleXMLElement $xmlObj)
    {
        $dataDescription = array();

        // put structs in its own variable that can be accessed independently.
        $this->_pcmlStructs = $xmlObj->xpath('struct');

        // looking for ->data and ->struct.
        $dataElements = $xmlObj->xpath('program/data');

        if ($dataElements) {
            foreach ($dataElements as $dataElement) {

                $dataDescription[] = $this->singlePcmlToArray($dataElement);
            }
        }

        return $dataDescription;
    }
1065550
public function postProcessContentObjectInitialization(ContentObjectRenderer &$parentObject)
    {
        if (!empty($parentObject->currentRecord)) {
            list($table) = explode(':', $parentObject->currentRecord);

            if (!empty($table) && $table != 'pages') {
                $this->findFrontendGroups($parentObject->data, $table);
            }
        }
    }
1264237
public static function createArray($inputXml, $version = '1.0', $encoding = 'UTF-8', $formatOutput = true)
    {
        $class = new self($version, $encoding, $formatOutput);
        $xml = $class->xml;

        if (is_string($inputXml)) {

            $parsed = $xml->loadXML($inputXml);

            if (! $parsed) {

                throw new \Exception('[XML2Array] Error parsing the XML string.');

            }

        } else {

            if (get_class($inputXml) !== 'DOMDocument') {

                throw new \Exception('[XML2Array] The input XML object should be of type: DOMDocument.');

            }

            $xml = $class->xml = $inputXml;
        }

        $array = [];
        $array[$xml->documentElement->tagName] = $class->convert($xml->documentElement);

        return $array;
    }