3 declare(strict_types=1);
49 public function __construct(
string $a_url,
string $a_prefix =
'',
int $a_timeout = 0,
string $a_encoding =
'utf-8')
53 $this->
logger = $DIC->logger()->wsrv();
55 if (!extension_loaded(
'xmlrpc')) {
61 $this->prefix = $a_prefix;
62 $this->timeout = $a_timeout;
63 $this->encoding = $a_encoding;
74 public function __call(
string $a_method, array $a_params)
77 $method_name = str_replace(
'_',
'.', $this->prefix . $a_method);
79 'verbosity' =>
'newlines_only',
80 'escaping' =>
'markup' 83 if ($this->encoding) {
86 $post_data = xmlrpc_encode_request($method_name, $a_params, $rpc_options);
91 $curl->setOpt(CURLOPT_HTTPHEADER, [
'Content-Type: text/xml']);
92 $curl->setOpt(CURLOPT_POST, (strlen($post_data) > 0));
93 $curl->setOpt(CURLOPT_POSTFIELDS, $post_data);
94 $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
96 if ($this->timeout > 0) {
97 $curl->setOpt(CURLOPT_TIMEOUT, $this->timeout);
99 $this->
logger->debug(
'RpcClient request to ' . $this->url .
' / ' . $method_name);
100 $xml_resp = $curl->exec();
103 'RpcClient could not connect to ' . $this->url .
' ' .
104 'Reason ' . $e->getCode() .
': ' . $e->getMessage()
110 $resp = xmlrpc_decode($xml_resp, $this->encoding);
113 if (is_array($resp) && xmlrpc_is_fault($resp)) {
114 $this->
logger->error(
'RpcClient recieved error ' . $resp[
'faultCode'] .
': ' . $resp[
'faultString']);
116 'RPC-Server returned fault message: ' .
117 $resp[
'faultString'],
static getLogger(string $a_component_id)
Get component logger.
__construct(string $a_url, string $a_prefix='', int $a_timeout=0, string $a_encoding='utf-8')
ilRpcClient constructor.
Class ilRpcClientException.
__call(string $a_method, array $a_params)
Magic caller to all RPC functions.