ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilRpcClient Class Reference

Class ilRpcClient. More...

+ Collaboration diagram for ilRpcClient:

Public Member Functions

 __construct ($a_url, $a_prefix='', $a_timeout=0, $a_encoding='utf-8')
 ilRpcClient constructor. More...
 
 __call ($a_method, $a_params)
 Magic caller to all RPC functions. More...
 

Protected Attributes

 $url
 
 $prefix = ''
 
 $timeout = 0
 
 $encoding = ''
 

Detailed Description

Class ilRpcClient.

Author
Fabian Wolf wolf@.nosp@m.leif.nosp@m.os.co.nosp@m.m

List of all known RPC methods...

RPCIndexHandler: @method void index() index(string $client, bool $bool) Prefix/Package: RPCIndexHandler @method void indexObjects() indexObjects(string $client, array $object_ids) Prefix/Package: RPCIndexHandler

RPCTransformationHandler: @method string ilFO2PDF() ilFO2PDF(string $fo_string) Prefix/Package: RPCTransformationHandler Return: base64

RPCSearchHandler: @method string searchMail() searchMail(string $client, int $user_id, string $query, int $mail_folder_id) Prefix/Package: RPCSearchHandler Return:xml @method string highlight() highlight(string $client, array $object_ids, string $query) Prefix/Package: RPCSearchHandler Return: string @method string searchUsers() searchUser(string $client, string $query) Prefix/Package: RPCSearchHandler Return: xml @method string search() search(string $client, string $query, int $page_nr) Prefix/Package: RPCSearchHandler Return: xml

Other: @method void ping() ping() Prefix/Package: RPCebug @method void refreshSettings() refreshSettings(string $client) Prefix/Package: RPCAdministration

Definition at line 30 of file class.ilRpcClient.php.

Constructor & Destructor Documentation

◆ __construct()

ilRpcClient::__construct (   $a_url,
  $a_prefix = '',
  $a_timeout = 0,
  $a_encoding = 'utf-8' 
)

ilRpcClient constructor.

Parameters
string$a_urlURL to connect to
string$a_prefixOptional prefix for method names
int$a_timeoutThe maximum number of seconds to allow ilRpcClient to connect.
string$a_encodingCharacter encoding
Exceptions
ilRpcClientException

Definition at line 49 of file class.ilRpcClient.php.

50 {
51 if (!extension_loaded('xmlrpc')) {
52 ilLoggerFactory::getLogger('wsrv')->error('RpcClient Xmlrpc extension not enabled');
53 throw new ilRpcClientException('Xmlrpc extension not enabled.', 50);
54 }
55
56 $this->url = (string) $a_url;
57 $this->prefix = (string) $a_prefix;
58 $this->timeout = (int) $a_timeout;
59 $this->encoding = (string) $a_encoding;
60 }
static getLogger($a_component_id)
Get component logger.
Class ilRpcClientException.

References ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ __call()

ilRpcClient::__call (   $a_method,
  $a_params 
)

Magic caller to all RPC functions.

Parameters
string$a_methodMethod name
array$a_paramsArgument array
Returns
mixed Returns either an array, or an integer, or a string, or a boolean according to the response returned by the XMLRPC method.
Exceptions
ilRpcClientException

Definition at line 70 of file class.ilRpcClient.php.

71 {
72 //prepare xml post data
73 $method_name = str_replace('_', '.', $this->prefix . $a_method);
74 $rpc_options = array(
75 'verbosity'=>'newlines_only',
76 'escaping' => 'markup'
77 );
78
79 if ($this->encoding) {
80 $rpc_options['encoding'] = $this->encoding;
81 }
82
83 $post_data = xmlrpc_encode_request($method_name, $a_params, $rpc_options);
84
85 //try to connect to the given url
86 try {
87 include_once './Services/WebServices/Curl/classes/class.ilCurlConnection.php';
88 $curl = new ilCurlConnection($this->url);
89 $curl->init();
90 $curl->setOpt(CURLOPT_HEADER, 'Content-Type: text/xml');
91 $curl->setOpt(CURLOPT_POST, (strlen($post_data) > 0));
92 $curl->setOpt(CURLOPT_POSTFIELDS, $post_data);
93 $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
94
95 if ($this->timeout > 0) {
96 $curl->setOpt(CURLOPT_TIMEOUT, $this->timeout);
97 }
98 ilLoggerFactory::getLogger('wsrv')->info('RpcClient request to ' . $this->url . ' / ' . $method_name);
99 $xml_resp = $curl->exec();
100 } catch (ilCurlConnectionException $e) {
101 ilLoggerFactory::getLogger('wsrv')->error('RpcClient could not connect to ' . $this->url . ' Reason ' . $e->getCode() . ': ' . $e->getMessage());
102 throw new ilRpcClientException($e->getMessage(), $e->getCode());
103 }
104
105 //prepare output, throw exception if rpc fault is detected
106 $resp = xmlrpc_decode($xml_resp, $this->encoding);
107
108 //xmlrpc_is_fault can just handle arrays as response
109 if (is_array($resp)&& xmlrpc_is_fault($resp)) {
110 ilLoggerFactory::getLogger('wsrv')->error('RpcClient recieved error ' . $resp['faultCode'] . ': ' . $resp['faultString']);
111 include_once './Services/WebServices/RPC/classes/class.ilRpcClientException.php';
112 throw new ilRpcClientException('RPC-Server returned fault message: ' . $resp['faultString'], $resp['faultCode']);
113 }
114
115 return $resp;
116 }

References $encoding, and ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Field Documentation

◆ $encoding

ilRpcClient::$encoding = ''
protected

Definition at line 39 of file class.ilRpcClient.php.

Referenced by __call().

◆ $prefix

ilRpcClient::$prefix = ''
protected

Definition at line 35 of file class.ilRpcClient.php.

◆ $timeout

ilRpcClient::$timeout = 0
protected

Definition at line 37 of file class.ilRpcClient.php.

◆ $url

ilRpcClient::$url
protected

Definition at line 33 of file class.ilRpcClient.php.


The documentation for this class was generated from the following file: