/**
* 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
{
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(),
* @param string $data
* @param string $returnType
* @param int $accept a bit-combination of self::ACCEPT_REQUEST, self::ACCEPT_RESPONSE, self::ACCEPT_VALUE
- * @return string
*/
public function parse($data, $returnType = self::RETURN_XMLRPCVALS, $accept = 3)
{
'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(),
/**
* xml parser handler function for opening element tags.
+ * @internal
* @param resource $parser
* @param string $name
* @param $attrs
return;
}
- // fall through voluntarily
+ // fall through voluntarily
case 'I4':
case 'INT':
case 'STRING':
/**
* xml parser handler function for close element tags.
+ * @internal
* @param resource $parser
* @param string $name
* @param int $rebuildXmlrpcvals >1 for rebuilding xmlrpcvals, 0 for rebuilding php values, -1 for xmlrpc-extension compatibility
/**
* Used in decoding xmlrpc requests/responses without rebuilding xmlrpc Values.
+ * @internal
* @param resource $parser
* @param string $name
*/
/**
* Used in decoding xmlrpc requests/responses while building xmlrpc-extension Values (plain php for all but base64 and datetime).
+ * @internal
* @param resource $parser
* @param string $name
*/
/**
* xml parser handler function for character data.
+ * @internal
* @param resource $parser
* @param string $data
*/
/**
* xml parser handler function for 'other stuff', ie. not char data or
* element start/end tag. In fact it only gets called on unknown entities...
+ * @internal
* @param $parser
* @param string data
*/