public function __call($fname, $args)
{
if ($this->scope != '') {
$rpc_method = "{$this->scope}.{$fname}";
} else {
$rpc_method = $fname;
}
$rpx = new \SimpleXMLElement('<methodCall/>');
$rpx->addChild('methodName', $rpc_method);
if (count($args) > 0) {
$params = $rpx->addchild('params');
foreach ($args as $arg) {
$param = $params->addchild('param');
XMLRPCUtils::encode_arg($param, $arg);
}
}
$request = new RemoteRequest($this->entrypoint, 'POST');
$request->add_header('Content-Type: text/xml;charset=utf-8');
$request->set_body($rpx->asXML());
$request->execute();
if ($request->executed()) {
$response = $request->get_response_body();
// @todo this should use the MultiByte class, not directly call mb_string functions
$enc = mb_detect_encoding($response);
$responseutf8 = mb_convert_encoding($response, 'UTF-8', $enc);
try {
// @todo this should use libxml_use_internal_errors() instead of trying to hide the PHP warning see the plugin info parsing code for an example
$bit = ini_get('error_reporting');
error_reporting($bit && !E_WARNING);
$responsexml = new \SimpleXMLElement($responseutf8);
error_reporting($bit);
$tmp = $responsexml->xpath('//params/param/value');
if (!($responsestruct = reset($tmp))) {
$tmp = $responsexml->xpath('//fault/value');
if (!($responsestruct = reset($tmp))) {
throw new \Exception(_t('Invalid XML response.'));
}
}
return XMLRPCUtils::decode_args($responsestruct);
} catch (\Exception $e) {
error_reporting($bit);
return false;
}
}
}