ffb66dda3cb955d0625286982cbd8460a46b63d6
[plcapi.git] / demo / client / simple_call.php
1 <?php
2 /**
3  * Helper function for the terminally lazy.
4  *
5  * @copyright (c) 2006-2015 G. Giunta
6  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
7  */
8
9 /**
10  * Takes a client object, a remote method name, and a variable numbers of
11  * php values, and calls the method with the supplied parameters. The
12  * parameters are native php values and the result is an xmlrpcresp object.
13  *
14  * Notes:
15  * The function encodes the received parameters using php_xmlrpc_encode:
16  * the limitations of automatic encoding apply to this function too);
17  *
18  * the type of the value returned by the function can be changed setting
19  * beforehand the 'return_type' member of the client object to 'phpvals' -
20  * see the manual for more details about this capability).
21  *
22  *
23  * @author Toth Istvan
24  *
25  * @param xmlrpc_client client object, properly set up to connect to server
26  * @param string remote function name
27  * @param mixed $parameter1
28  * @param mixed $parameter2
29  * @param mixed $parameter3 ...
30  *
31  * @return xmlrpcresp or false on error
32  */
33 function xmlrpccall_simple()
34 {
35     if (func_num_args() < 2) {
36         // Incorrect
37         return false;
38     } else {
39         $varargs = func_get_args();
40         $client = array_shift($varargs);
41         $remote_function_name = array_shift($varargs);
42         if (!is_a($client, 'xmlrpc_client') || !is_string($remote_function_name)) {
43             return false;
44         }
45
46         $xmlrpcval_array = array();
47         foreach ($varargs as $parameter) {
48             $xmlrpcval_array[] = php_xmlrpc_encode($parameter);
49         }
50
51         return $client->send(new xmlrpcmsg($remote_function_name, $xmlrpcval_array));
52     }
53 }