1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @author Robin J. Rogge <[email protected]> |
||
5 | * @link https://github.com/pradosoft/prado |
||
6 | * @license https://github.com/pradosoft/prado/blob/master/LICENSE |
||
7 | * @since 3.2 |
||
8 | */ |
||
9 | |||
10 | namespace Prado\Util; |
||
11 | |||
12 | /** |
||
13 | * TXmlRpcClient class |
||
14 | * |
||
15 | * Note: When using setIsNotification(true), *every* following request is also |
||
16 | * considered to be a notification until you use setIsNotification(false). |
||
17 | * |
||
18 | * Usage: |
||
19 | * <pre> |
||
20 | * $_rpcClient = new TXmlRpcClient('http://remotehost/rpcserver'); |
||
21 | * $_rpcClient->remoteMethod($param, $otherParam); |
||
22 | * </pre> |
||
23 | * |
||
24 | * @author Robin J. Rogge <[email protected]> |
||
25 | * @since 3.2 |
||
26 | */ |
||
27 | class TXmlRpcClient extends TRpcClient |
||
28 | { |
||
29 | // magics |
||
30 | |||
31 | /** |
||
32 | * @param string $method RPC method name |
||
33 | * @param array $parameters RPC method parameters |
||
34 | * @throws TRpcClientRequestException if the client fails to connect to the server |
||
35 | * @throws TRpcClientResponseException if the response represents an RPC fault |
||
36 | * @return mixed RPC request result |
||
37 | */ |
||
38 | public function __call($method, $parameters) |
||
39 | { |
||
40 | // send request |
||
41 | $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'text/xml'); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
42 | |||
43 | // skip response handling if the request was just a notification request |
||
44 | if ($this->getIsNotification()) { |
||
45 | return true; |
||
46 | } |
||
47 | |||
48 | // decode response |
||
49 | if (($_response = xmlrpc_decode($_response)) === null) { |
||
50 | throw new TRpcClientResponseException('Empty response received'); |
||
51 | } |
||
52 | |||
53 | // handle error response |
||
54 | if (xmlrpc_is_fault($_response)) { |
||
55 | throw new TRpcClientResponseException($_response['faultString'], $_response['faultCode']); |
||
56 | } |
||
57 | |||
58 | return $_response; |
||
59 | } |
||
60 | |||
61 | // methods |
||
62 | |||
63 | /** |
||
64 | * @param string $method method name |
||
65 | * @param array $parameters method parameters |
||
66 | */ |
||
67 | public function encodeRequest($method, $parameters) |
||
68 | { |
||
69 | return xmlrpc_encode_request($method, $parameters); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Creates an instance of TXmlRpcClient |
||
74 | * @param mixed $type unused |
||
75 | * @param string $serverUrl url of the rpc server |
||
76 | * @param bool $isNotification whether the requests are considered to be notifications (completely ignoring the response) (default: false) |
||
77 | */ |
||
78 | public static function create($type, $serverUrl, $isNotification = false) |
||
79 | { |
||
80 | return new self($serverUrl, $isNotification); |
||
81 | } |
||
82 | } |
||
83 |