Refactor the Wrapper class to generate closures by default and avoid usage of 'eval'
[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: see file license.txt
7  */
8
9 include_once __DIR__ . "/../../src/Autoloader.php";
10 PhpXmlRpc\Autoloader::register();
11
12 /**
13  * Takes a client object, a remote method name, and a variable numbers of
14  * php values, and calls the method with the supplied parameters. The
15  * parameters are native php values and the result is an xmlrpcresp object.
16  *
17  * Notes:
18  * The function encodes the received parameters using php_xmlrpc_encode:
19  * the limitations of automatic encoding apply to this function too);
20  *
21  * the type of the value returned by the function can be changed setting
22  * beforehand the 'return_type' member of the client object to 'phpvals' -
23  * see the manual for more details about this capability).
24  *
25  *
26  * @author Toth Istvan
27  *
28  * @param xmlrpc_client client object, properly set up to connect to server
29  * @param string remote function name
30  * @param mixed $parameter1
31  * @param mixed $parameter2
32  * @param mixed $parameter3 ...
33  *
34  * @return xmlrpcresp or false on error
35  */
36 function xmlrpccall_simple()
37 {
38     if (func_num_args() < 2) {
39         // Incorrect
40         return false;
41     } else {
42         $varargs = func_get_args();
43         $client = array_shift($varargs);
44         $remote_function_name = array_shift($varargs);
45         if (!is_a($client, 'xmlrpc_client') || !is_string($remote_function_name)) {
46             return false;
47         }
48
49         $valueArray = array();
50         $encoder = new PhpXmlRpc\Encoder();
51         foreach ($varargs as $parameter) {
52             $valueArray[] = $encoder->encode($parameter);
53         }
54
55         return $client->send(new PhpXmlRpc\Request($remote_function_name, $valueArray));
56     }
57 }