ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRpcClient Class Reference

Class ilRpcClient. More...

+ Collaboration diagram for ilRpcClient:

Public Member Functions

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

Protected Attributes

string $url
 
string $prefix = ''
 
int $timeout = 0
 
string $encoding = ''
 
ilLogger $logger
 

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 46 of file class.ilRpcClient.php.

Constructor & Destructor Documentation

◆ __construct()

ilRpcClient::__construct ( string  $a_url,
string  $a_prefix = '',
int  $a_timeout = 0,
string  $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 63 of file class.ilRpcClient.php.

64 {
65 global $DIC;
66
67 $this->logger = $DIC->logger()->wsrv();
68
69 if (!extension_loaded('xmlrpc')) {
70 ilLoggerFactory::getLogger('wsrv')->error('RpcClient Xmlrpc extension not enabled');
71 throw new ilRpcClientException('Xmlrpc extension not enabled.', 50);
72 }
73
74 $this->url = $a_url;
75 $this->prefix = $a_prefix;
76 $this->timeout = $a_timeout;
77 $this->encoding = $a_encoding;
78 }
static getLogger(string $a_component_id)
Get component logger.
Class ilRpcClientException.
global $DIC
Definition: shib_login.php:26

References $DIC, ilLoggerFactory\getLogger(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ __call()

ilRpcClient::__call ( string  $a_method,
array  $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 88 of file class.ilRpcClient.php.

89 {
90 //prepare xml post data
91 $method_name = str_replace('_', '.', $this->prefix . $a_method);
92 $rpc_options = array(
93 'verbosity' => 'newlines_only',
94 'escaping' => 'markup'
95 );
96
97 if ($this->encoding) {
98 $rpc_options['encoding'] = $this->encoding;
99 }
100 $post_data = xmlrpc_encode_request($method_name, $a_params, $rpc_options);
101 //try to connect to the given url
102 try {
103 $curl = new ilCurlConnection($this->url);
104 $curl->init(false);
105 $curl->setOpt(CURLOPT_HTTPHEADER, ['Content-Type: text/xml']);
106 $curl->setOpt(CURLOPT_POST, (strlen($post_data) > 0));
107 $curl->setOpt(CURLOPT_POSTFIELDS, $post_data);
108 $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
109
110 if ($this->timeout > 0) {
111 $curl->setOpt(CURLOPT_TIMEOUT, $this->timeout);
112 }
113 $this->logger->debug('RpcClient request to ' . $this->url . ' / ' . $method_name);
114 $xml_resp = $curl->exec();
115 } catch (ilCurlConnectionException $e) {
116 $this->logger->error(
117 'RpcClient could not connect to ' . $this->url . ' ' .
118 'Reason ' . $e->getCode() . ': ' . $e->getMessage()
119 );
120 throw new ilRpcClientException($e->getMessage(), $e->getCode());
121 }
122
123 //prepare output, throw exception if rpc fault is detected
124 $resp = xmlrpc_decode($xml_resp, $this->encoding);
125
126 //xmlrpc_is_fault can just handle arrays as response
127 if (is_array($resp) && xmlrpc_is_fault($resp)) {
128 $this->logger->error('RpcClient recieved error ' . $resp['faultCode'] . ': ' . $resp['faultString']);
129 throw new ilRpcClientException(
130 'RPC-Server returned fault message: ' .
131 $resp['faultString'],
132 $resp['faultCode']
133 );
134 }
135 return $resp;
136 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References Vendor\Package\$e, $encoding, XapiProxy\$resp, and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Field Documentation

◆ $encoding

string ilRpcClient::$encoding = ''
protected

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

Referenced by __call().

◆ $logger

ilLogger ilRpcClient::$logger
protected

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

◆ $prefix

string ilRpcClient::$prefix = ''
protected

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

◆ $timeout

int ilRpcClient::$timeout = 0
protected

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

◆ $url

string ilRpcClient::$url
protected

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


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