Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : XML-RPC Functions : xmlrpc_server_register_method

xmlrpc_server_register_method

Register a PHP function to resource method matching method_name (PHP 4 >= 4.0.7, PHP 5)
bool xmlrpc_server_register_method ( resource server, string method_name, string function )

Warning:

This function is EXPERIMENTAL. The behaviour of this function, the name of this function, and anything else documented about this function may change without notice in a future release of PHP. Use this function at your own risk.

Warning:

This function is currently not documented; only the argument list is available.

Related Examples ( Source code ) » xmlrpc_server_register_method


Code Examples / Notes » xmlrpc_server_register_method

dante

To register a callback to a 'static' function within the same class, consider a syntax like the following:
<code>
$callback = array (__CLASS__, "my_function_name");
xmlrpc_server_register_method($xmlrpc_server, "my_function", $callback);
</code>
Doing it this way makes it easier to rename your class later.


giunta dot gaetano

To have an xmlrpc fault response programatically generated by the server, the php function registered 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!');
}


eiriks

Remember that you can't do like Chrigu and Nate said if you want to add methods from a static class (Hence you can't create any instances of it).
A workaround is to create lambda functions calling the
methods:
// Our static handler class
static class MyHandler
{
   public function getPrice($item)
   {
       $prices = array("apple" => 4, "orange" => 5);
       return $prices[$item];
   }
   public function buy($item, $number)
   {
       $price = self::getPrice($item) * $number;
       do_thing_to_sell_the_item();
       return $price;
   }
}
// Use reflection to get method names and parameters
$mirror = new ReflectionClass("MyHandler");
foreach ($mirror->getMethods() as $method)
{
   // Create new "lambda" function for each method
   
   // Generate argument list
   $args = array();
   foreach ($method->getParameters() as $param)
   {
       $args[] = '$'.$param->getName();
   }
   $args = implode(',', $args);
   
   // Generate code
   $methodname = $method->getName();
   $code = "return {$real_class}::{$methodname}({$args});";
   
   // Create function, retrieve function name
   $function_name = create_function($args, $code);
   // Register the function
   xmlrpc_server_register_method($myserver, $methodname, $function_name);
}


nyvsld

prototype of registered function:
function method_impl(string $method_name, array $params, array $user_data);
$method_name
   the public method name, known by calling client
$params
   parameters specified by calling client
$user_data
   any local data, passed by `xmlrpc_server_call_method'


nate parsons

In case its not completely obvious what Chrigu meant,
You can register a method inside your class by doing the following:
xml_rpc_server_register_methode($xmlrpc_server, "myClientCall", array(&$this, "handleClientCallFunc"));
where $this == the magic class $this. =)


18-nov-2002 06:40

Here is an example how to register a class methode:
xml_rpc_server_register_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 forget the '&'!
hope this may be useful...
Chrigu


Change Language


Follow Navioo On Twitter
xmlrpc_decode_request
xmlrpc_decode
xmlrpc_encode_request
xmlrpc_encode
xmlrpc_get_type
xmlrpc_is_fault
xmlrpc_parse_method_descriptions
xmlrpc_server_add_introspection_data
xmlrpc_server_call_method
xmlrpc_server_create
xmlrpc_server_destroy
xmlrpc_server_register_introspection_callback
xmlrpc_server_register_method
xmlrpc_set_type
eXTReMe Tracker