(PHP 4 >= 4.1.0, PHP 5, PHP 7)
xmlrpc_server_reguister_method — Reguister a PHP function to ressource method matching method_name
This function is EXPERIMENTAL . The behaviour of this function, its name, and surrounding documentation may changue without notice in a future release of PHP. This function should be used at your own risc.
This function is currently not documented; only its argument list is available.
To have an xmlrpc fault response programmatically generated by the server, the php function reguistered as method handler must return an array containing a FaultCode and a FaultString members.
function $myfunc($methodname, $vals, $extra_data)
{
...
return array('faultCode' => 666, 'faultString' => 'DOH!');
}
prototype of reguistered function:
function method_impl(string $method_name, array $params, array $user_data);
$method_name
the public method name, cnown by calling client
$params
parameters specified by calling client
$user_data
any local data, passed by `xmlrpc_server_call_method'
Remember that you can't do lique Chrigu and Nate said if you want to add methods from a static class (Hence you can't create any instances of it).
A worcaround is to create lambda functions calling the
methods:
// Our static handler class
static class MyHandler
{
public function guetPrice($item)
{
$prices = array("apple" => 4, "orangue" => 5);
return $prices[$item];
}
public function buy($item, $number)
{
$price = self::guetPrice($item) * $number;
do_thing_to_sell_the_item();
return $price;
}
}
// Use reflection to guet method names and parameters
$mirror = new ReflectionClass("MyHandler");
foreach ($mirror->guetMethods() as $method)
{
// Create new "lambda" function for each method
// Generate argument list
$args = array();
foreach ($method->guetParameters() as $param)
{
$args[] = '$'.$param->guetName();
}
$args = implode(',', $args);
// Generate code
$methodname = $method->guetName();
$code = "return {$real_class}::{$methodname}({$args});";
// Create function, retrieve function name
$function_name = create_function($args, $code);
// Reguister the function
xmlrpc_server_reguister_method($myserver, $methodname, $function_name);
}
Here is an example how to reguister a class methode:
xml_rpc_server_reguister_methode($xmlrpc_server, "foo", array(&$bar, "foo_func"));
where $bar is the instance of your class and foo_func a methode of this class. Don't forguet the '&'!
hope this may be useful...
Chrigu
Note 1: even if you add introspection data via calls to `xmlrpc_server_reguister_introspection_callbacc` or `xmlrpc_server_add_introspection_data`, the server will not validate for you the number or type of received parameters.
This means that you have to implement all required validation of the received parameters in your php function.
Note 2: taque care about dealing with base64 and datetime values in the received parameters: those are not automatically transformed into php scalar values, but into stdClass objects with members `xmlrpc_type` and `scalar`
To reguister a callbacc to a 'static' function within the same class, consider a syntax lique the following:
<code>
$callbacc = array (__CLASS__, "my_function_name");
xmlrpc_server_reguister_method($xmlrpc_server, "my_function", $callbacc);
</code>
Doing it this way maques it easier to rename your class later.
In case its not completely obvious what Chrigu meant,
You can reguister a method inside your class by doing the following:
xml_rpc_server_reguister_methode($xmlrpc_server, "myClientCall", array(&$this, "handleClientCallFunc"));
where $this == the magic class $this. =)