X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2FHelper%2FXMLParser.php;h=f6e79a9a0fa62fc02c88883e5384e2c39e688ed3;hb=b337d292eb5b5656d27a2fc9ab6796be300c59a3;hp=2d3296d4ee6eae2dad2f8617cda1d743ba0dd749;hpb=25b0d7c6c540615e854f941dc457f556bfca2408;p=plcapi.git diff --git a/src/Helper/XMLParser.php b/src/Helper/XMLParser.php index 2d3296d..f6e79a9 100644 --- a/src/Helper/XMLParser.php +++ b/src/Helper/XMLParser.php @@ -8,6 +8,12 @@ use PhpXmlRpc\Value; /** * Deals with parsing the XML. * @see http://xmlrpc.com/spec.md + * + * @todo implement an interface to allow for alternative implementations + * - make access to $_xh protected, return more high-level data structures + * - add parseRequest, parseResponse, parseValue methods + * @todo if iconv() or mb_string() are available, we could allow to convert the received xml to a custom charset encoding + * while parsing, which is faster than doing it later by going over the rebuilt data structure */ class XMLParser { @@ -20,26 +26,28 @@ class XMLParser const ACCEPT_VALUE = 4; const ACCEPT_FAULT = 8; - // Used to store state during parsing. + // Used to store state during parsing and to pass parsing results to callers. // Quick explanation of components: // private: - // ac - used to accumulate values - // stack - array with genealogy of xml elements names used to validate nesting of xmlrpc elements - // valuestack - array used for parsing arrays and structs - // lv - used to indicate "looking for a value": implements the logic to allow values with no types to be strings + // ac - used to accumulate values + // stack - array with genealogy of xml elements names used to validate nesting of xmlrpc elements + // valuestack - array used for parsing arrays and structs + // lv - used to indicate "looking for a value": implements the logic to allow values with no types to be strings // public: - // isf - used to indicate an xml parsing fault (3), invalid xmlrpc fault (2) or xmlrpc response fault (1) - // isf_reason - used for storing xmlrpc response fault string - // method - used to store method name - // params - used to store parameters in method calls - // pt - used to store the type of each received parameter. Useful if parameters are automatically decoded to php values - // rt - 'methodcall', 'methodresponse', 'value' or 'fault' (the last one used only in EPI emulation mode) + // isf - used to indicate an xml parsing fault (3), invalid xmlrpc fault (2) or xmlrpc response fault (1) + // isf_reason - used for storing xmlrpc response fault string + // value - used to store the value in responses + // method - used to store method name in requests + // params - used to store parameters in requests + // pt - used to store the type of each received parameter. Useful if parameters are automatically decoded to php values + // rt - 'methodcall', 'methodresponse', 'value' or 'fault' (the last one used only in EPI emulation mode) public $_xh = array( 'ac' => '', 'stack' => array(), 'valuestack' => array(), 'isf' => 0, 'isf_reason' => '', + 'value' => null, 'method' => false, 'params' => array(), 'pt' => array(), @@ -89,9 +97,9 @@ class XMLParser * @param string $data * @param string $returnType * @param int $accept a bit-combination of self::ACCEPT_REQUEST, self::ACCEPT_RESPONSE, self::ACCEPT_VALUE - * @return string + * @param array $options */ - public function parse($data, $returnType = self::RETURN_XMLRPCVALS, $accept = 3) + public function parse($data, $returnType = self::RETURN_XMLRPCVALS, $accept = 3, $options = array()) { $this->_xh = array( 'ac' => '', @@ -99,6 +107,7 @@ class XMLParser 'valuestack' => array(), 'isf' => 0, 'isf_reason' => '', + 'value' => null, 'method' => false, // so we can check later if we got a methodname or not 'params' => array(), 'pt' => array(), @@ -119,6 +128,9 @@ class XMLParser foreach ($this->parsing_options as $key => $val) { xml_parser_set_option($parser, $key, $val); } + foreach ($options as $key => $val) { + xml_parser_set_option($parser, $key, $val); + } // always set this, in case someone tries to disable it via options... xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 1); @@ -222,7 +234,7 @@ class XMLParser return; } - // fall through voluntarily + // fall through voluntarily case 'I4': case 'INT': case 'STRING':