ILIAS  release_8 Revision v8.24
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 32 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 49 of file class.ilRpcClient.php.

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

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

75 {
76 //prepare xml post data
77 $method_name = str_replace('_', '.', $this->prefix . $a_method);
78 $rpc_options = array(
79 'verbosity' => 'newlines_only',
80 'escaping' => 'markup'
81 );
82
83 if ($this->encoding) {
84 $rpc_options['encoding'] = $this->encoding;
85 }
86 $post_data = xmlrpc_encode_request($method_name, $a_params, $rpc_options);
87 //try to connect to the given url
88 try {
89 $curl = new ilCurlConnection($this->url);
90 $curl->init(false);
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);
95
96 if ($this->timeout > 0) {
97 $curl->setOpt(CURLOPT_TIMEOUT, $this->timeout);
98 }
99 $this->logger->debug('RpcClient request to ' . $this->url . ' / ' . $method_name);
100 $xml_resp = $curl->exec();
101 } catch (ilCurlConnectionException $e) {
102 $this->logger->error(
103 'RpcClient could not connect to ' . $this->url . ' ' .
104 'Reason ' . $e->getCode() . ': ' . $e->getMessage()
105 );
106 throw new ilRpcClientException($e->getMessage(), $e->getCode());
107 }
108
109 //prepare output, throw exception if rpc fault is detected
110 $resp = xmlrpc_decode($xml_resp, $this->encoding);
111
112 //xmlrpc_is_fault can just handle arrays as response
113 if (is_array($resp) && xmlrpc_is_fault($resp)) {
114 $this->logger->error('RpcClient recieved error ' . $resp['faultCode'] . ': ' . $resp['faultString']);
115 throw new ilRpcClientException(
116 'RPC-Server returned fault message: ' .
117 $resp['faultString'],
118 $resp['faultCode']
119 );
120 }
121 return $resp;
122 }

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

Referenced by __call().

◆ $logger

ilLogger ilRpcClient::$logger
protected

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

◆ $prefix

string ilRpcClient::$prefix = ''
protected

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

◆ $timeout

int ilRpcClient::$timeout = 0
protected

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

◆ $url

string ilRpcClient::$url
protected

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


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