ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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: void index() index(string $client, bool $bool) Prefix/Package: RPCIndexHandler void indexObjects() indexObjects(string $client, array $object_ids) Prefix/Package: RPCIndexHandler

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

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

Other: void ping() ping() Prefix/Package: RPCebug 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.

References ilLoggerFactory\getLogger(), and string.

50  {
51  if(!extension_loaded('xmlrpc'))
52  {
53  ilLoggerFactory::getLogger('wsrv')->error('RpcClient Xmlrpc extension not enabled');
54  throw new ilRpcClientException('Xmlrpc extension not enabled.', 50);
55  }
56 
57  $this->url = (string) $a_url;
58  $this->prefix = (string) $a_prefix;
59  $this->timeout = (int) $a_timeout;
60  $this->encoding = (string) $a_encoding;
61  }
Add rich text string
The name of the decorator.
Class ilRpcClientException.
static getLogger($a_component_id)
Get component logger.
+ 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 71 of file class.ilRpcClient.php.

References $encoding, array, and ilLoggerFactory\getLogger().

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