Fix leftovers from branch merging; remove more php closing tags; bump up requirements...
[plcapi.git] / demo / client / simple_call.php
1 <?php
2 /**
3  * Helper function for the terminally lazy
4  *
5  * @copyright (c) 2006-2014 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      * @return xmlrpcresp or false on error
31      */
32     function xmlrpccall_simple()
33     {
34         if(func_num_args() < 2)
35         {
36             // Incorrect
37             return false;
38         }
39         else
40         {
41             $varargs = func_get_args();
42             $client = array_shift($varargs);
43             $remote_function_name = array_shift($varargs);
44             if (!is_a($client, 'xmlrpc_client') || !is_string($remote_function_name))
45             {
46                 return false;
47             }
48
49             $xmlrpcval_array = array();
50             foreach($varargs as $parameter)
51             {
52                 $xmlrpcval_array[] = php_xmlrpc_encode($parameter);
53             }
54
55             return $client->send(new xmlrpcmsg($remote_function_name, $xmlrpcval_array));
56         }
57     }