* xmlrpc value into the appropriate object (a.k.a. deserialize).
*
* @param string $xmlVal
- * @param array $options
+ * @param array $options unused atm
* @return Value|Request|Response|false false on error, or an instance of either Value, Request or Response
*
* @todo is this a good name/class for this method? It does something quite different from 'decode' after all
* (returning objects vs returns plain php values)... In fact, it belongs rather to a Parser class
- * Feature creep -- we should allow an option to return php native types instead of PhpXmlRpc objects instances
+ * @todo feature creep -- we should allow an option to return php native types instead of PhpXmlRpc objects instances
+ * @todo feature creep -- allow source charset to be passed in as an option, in case the xml misses its declaration
+ * @todo feature creep -- allow expected type (val/req/resp) to be passed in as an option
*/
public function decodeXml($xmlVal, $options = array())
{
if ($valEncoding != '') {
// Since parsing will fail if
- // - charset is not specified in the xml prologue,
+ // - charset is not specified in the xml declaration,
// - the encoding is not UTF8 and
// - there are non-ascii chars in the text,
// we try to work round that...
}
// What if internal encoding is not in one of the 3 allowed? We use the broadest one, ie. utf8!
- if (!in_array(PhpXmlRpc::$xmlrpc_internalencoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) {
- /// @todo emit a warning
- $parserOptions = array(XML_OPTION_TARGET_ENCODING => 'UTF-8');
- } else {
+ if (in_array(PhpXmlRpc::$xmlrpc_internalencoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) {
$parserOptions = array(XML_OPTION_TARGET_ENCODING => PhpXmlRpc::$xmlrpc_internalencoding);
+ } else {
+ $parserOptions = array(XML_OPTION_TARGET_ENCODING => 'UTF-8', 'target_charset' => PhpXmlRpc::$xmlrpc_internalencoding);
}
$xmlRpcParser = $this->getParser();
'ac' => '',
'stack' => array(),
'valuestack' => array(),
+
'isf' => 0,
'isf_reason' => '',
'value' => null,
}
/**
- * @param int[] $options passed to the xml parser
+ * @param array $options passed to the xml parser
*/
public function __construct(array $options = array())
{
* @param int $accept a bit-combination of self::ACCEPT_REQUEST, self::ACCEPT_RESPONSE, self::ACCEPT_VALUE
* @param array $options integer-key options are passed to the xml parser, in addition to the options received in
* the constructor. String-key options are used independently
- * @return void
+ * @return void the caller has to look into $this->_xh to find the results
* @throws \Exception this can happen if a callback function is set and it does throw (ie. we do not catch exceptions)
*/
public function parse($data, $returnType = self::RETURN_XMLRPCVALS, $accept = 3, $options = array())
'ac' => '',
'stack' => array(),
'valuestack' => array(),
+
'isf' => 0,
'isf_reason' => '',
'value' => null,
// in case there is charset conversion required, do it here, to catch both cases of string values
if (isset($this->current_parsing_options['target_charset']) && $this->_xh['vt'] === Value::$xmlrpcString) {
- $this->_xh['vt'] = mb_convert_encoding($this->_xh['vt'], $this->current_parsing_options['target_charset'], 'UTF-8');
+ $this->_xh['value'] = mb_convert_encoding($this->_xh['value'], $this->current_parsing_options['target_charset'], 'UTF-8');
}
if ($rebuildXmlrpcvals > 0) {
*
* @param string $xmlChunk
* @return bool
+ *
+ * @todo rename to hasEncodingDeclaration
*/
public static function hasEncoding($xmlChunk)
{
/// @todo move this block of code into the XMLParser
if ($respEncoding != '') {
- // Since parsing will fail if charset is not specified in the xml prologue,
+ // Since parsing will fail if charset is not specified in the xml declaration,
// the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
// The following code might be better for mb_string enabled installs, but makes the lib about 200% slower...
//if (!is_valid_charset($respEncoding, array('UTF-8')))
/// @todo move this block of code into the XMLParser
if ($reqEncoding != '') {
// Since parsing will fail if
- // - charset is not specified in the xml prologue,
+ // - charset is not specified in the xml declaration,
// - the encoding is not UTF8 and
// - there are non-ascii chars in the text,
// we try to work round that...