<?PHP
/*
What:
Sample XMLRPC implementation server, that calls a defined function, object method, or includes a object on call.
It uses the format ClassName.MethodName The '.' dot in a XML request methodName parameter separates a classname and a methodname.
Credits:
This comes builtin to PHPortal (c) 2002 - Application Builder LGPL (free non-commercial)
(http://dev.4arrow.com) of http://4Arrow.com by Michael Glazer http://coding.4arrow.com
PHPortal has RPC awareness and can automatically detect and response in kind to a XML-RPC request.
Requires:
http://www.php.net/manual/en/ref.xmlrpc.php
Info:
http://xmlrpc-epi.sourceforge.net/
http://xmlrpc.com/
Example:
$args=array(
xml => $HTTP_RAW_POST_DATA
);
if($REQUEST_METHOD=="POST" && !strncmp($CONTENT_TYPE,"text/xml",8)){
$xmlrpc = new XPC_xmlrpc($args);
Header("Content-Type: text/xml");
echo$xmlrpc->_RET;exit;
}//end if
else{
echo'GET Method not allowed!';exit;
}//end else
include_once("test.php");
Class test{
function tester($args=''){
if(is_array($args)){
foreach($args as $k => $v){
$arr[$k]=$v;
}
}
else{
$arr=array("Hello World!",time());
}
return $arr;
}
}
*/
Class XPC_xmlrpc{
var $_XML,$_RET,$_TYPE='xml',$_NAME='xmlrpc',$_ARGS=array();
function XPC_xmlrpc($args=''){
$this->_XML=$args['xml'];
$this->run($args);
}//end XPC_xmlrpc constructor method
function run($args=''){
$xmlrpc_server = xmlrpc_server_create();
$arr = xmlrpc_parse_method_descriptions($this->_XML);
if($xmlrpc_server){
if(!xmlrpc_server_register_method($xmlrpc_server,$arr['methodName'],'handler')){
die("<h2>method registration failed.</h2>");
}//end if
$this->_RET = xmlrpc_server_call_method($xmlrpc_server,$this->_XML,array(you,love,me),array(output_type=>$this->_TYPE));
$success = xmlrpc_server_destroy($xmlrpc_server);
}//end if
}//end run method
}//End XPC_xmlrpc Class
function handler($method_name,$params,$app_data){
if(preg_match("/^(.+)\.(.+)$/",$method_name,$match)){
$class = str_replace(".","_",$match[1]);
$name = strtolower($match[2]);
if(!class_exists($class)){
return array("3","unable to find class '$class'");
}//end if
elseif(array_search($name,get_class_methods($class))===null){
return array("4","unable to find method '$name' in class '$class'");
}//end else if
else{
$handler = array(new $class, $match[2]);
}//end else
}//end if
else{
$handler = $method_name;
}//end else
if(is_array($handler)){
$ret = call_user_func_array($handler,array(arra=>array_merge($app_data,$params)));
}//end if
else{
$ret = call_user_func_array($handler,array(arra=>array_merge($app_data,$params)));
}//end else
return $ret;
}//End handler method
?>
|
|