AAAAhome/academiac/www/plugins/vmpayment/sofort/sofort/library/helper/xml_to_array.php000060400000017440151376511320024702 0ustar00 '€', ); /** * Loads XML into array representation. * @param string $input * @param int $maxDepth * @throws XmlToArrayException */ public function __construct($input, $maxDepth = 20) { if (!is_string($input)) throw new XmlToArrayException('No valid input.'); $this->_maxDepth = $maxDepth; $XMLParser = xml_parser_create(); xml_parser_set_option($XMLParser, XML_OPTION_SKIP_WHITE, false); xml_parser_set_option($XMLParser, XML_OPTION_CASE_FOLDING, false); xml_parser_set_option($XMLParser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); xml_set_character_data_handler($XMLParser, array($this, '_contents')); xml_set_default_handler($XMLParser, array($this, '_default')); xml_set_element_handler($XMLParser, array($this, '_start'), array($this, '_end')); xml_set_external_entity_ref_handler($XMLParser, array($this, '_externalEntity')); xml_set_notation_decl_handler($XMLParser, array($this, '_notationDecl')); xml_set_processing_instruction_handler($XMLParser, array($this, '_processingInstruction')); xml_set_unparsed_entity_decl_handler($XMLParser, array($this, '_unparsedEntityDecl')); if (!xml_parse($XMLParser, $input, true)) { $errorCode = xml_get_error_code($XMLParser); $message = sprintf('%s. line: %d, char: %d'.($this->_tagStack ? ', tag: %s' : ''), xml_error_string($errorCode), xml_get_current_line_number($XMLParser), xml_get_current_column_number($XMLParser)+1, implode('->', $this->_tagStack)); xml_parser_free($XMLParser); throw new XmlToArrayException($message, $errorCode); } xml_parser_free($XMLParser); } /** * * Log messages (debugging purpose) * @param string $msg * @param int $type */ public function log($msg, $type = 2) { if (class_exists('Object')) { !($this->_Object instanceof Object) && $this->_Object = new Object(); return $this->_Object->log($msg, $type); } return false; } /** * Returns parsed XML as array structure * @return array */ public function toArray($simpleStructure = false) { return $this->_CurrentXmlToArrayNode->render($simpleStructure); } /** * Static entry point * @param string $input * @param bool $simpleStructure * @param int $maxDepth only parse XML to the provided depth * @return array * @throws XmlToArrayException */ public static function render($input, $simpleStructure = false, $maxDepth = 20) { $Instance = new XmlToArray($input, $maxDepth); return $Instance->toArray($simpleStructure); } /** * Handles cdata of the XML (user data between the tags) * @param resource $parser a resource handle of the XML parser * @param string $data */ private function _contents($parser, $data) { if (trim($data) !== '' && $this->_CurrentXmlToArrayNode instanceof XmlToArrayNode) $this->_CurrentXmlToArrayNode->setData($data); } /** * Default handler for all other XML sections not implemented as callback * @param resource $parser a resource handle of the XML parser * @param mixed $data * @throws XmlToArrayException */ private function _default($parser, $data) { $data = trim($data); if (in_array($data, get_html_translation_table(HTML_ENTITIES))) { $this->_CurrentXmlToArrayNode instanceof XmlToArrayNode && $this->_CurrentXmlToArrayNode->setData(html_entity_decode($data)); } elseif ($data && isset(self::$_htmlEntityExceptions[$data])) { $this->_CurrentXmlToArrayNode instanceof XmlToArrayNode && $this->_CurrentXmlToArrayNode->setData(self::$_htmlEntityExceptions[$data]); } elseif ($data && is_string($data) && strpos($data, '