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