downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Introduction> <SoapVar::SoapVar
Last updated: Fri, 20 Nov 2009

view this page in

XML-RPC



add a note add a note User Contributed Notes
XML-RPC
aim at secoya dot dk
15-Sep-2009 03:08
Here is a little wrapper class I just developed. It simply calls the methods you register with it.

<?php
class XMLRPCServer {
   
    private
$serverHandler;
   
    private
$externalFunctions;
   
    public function
__construct() {
       
$this->serverHandler = xmlrpc_server_create();
       
$this->externalFunctions = array();
    }
   
    public function
registerMethod($externalName, $function, $parameterNames) {
        if(
$function == null) $function = $externalName;
       
xmlrpc_server_register_method($this->serverHandler, $externalName, array(&$this, 'callMethod'));
       
$this->externalFunctions[$externalName] =
            array(
'function'       => $function,
                 
'parameterNames' => $parameterNames);
    }
   
    public function
callMethod($functionName, $parametersFromRequest) {
       
$function = $this->externalFunctions[$functionName]['function'];
       
$parameterNames = $this->externalFunctions[$functionName]['parameterNames'];
       
$parameters = array();
        foreach(
$parameterNames as $parameterName) {
           
$parameters[] = $parametersFromRequest[0][$parameterName];
        }
        return
call_user_func_array($function, $parameters);
    }
   
    public function
computeAnswer() {
        return
xmlrpc_server_call_method($this->serverHandler, file_get_contents('php://input'), null);
    }
}

// USAGE EXAMPLE HERE
$xmlRPCServer = new XMLRPCServer();
$someServer = new SomeXmlRPCServer($xmlRPCServer);
$answer = $xmlRPCServer->computeAnswer();
header('Content-Type: text/xml');
print(
$answer);
class
SomeXmlRPCServer{
   
    private
$xmlRPCServer;
   
    public function
__construct($xmlRPCServer) {
       
$this->xmlRPCServer = $xmlRPCServer;
       
$this->xmlRPCServer->registerMethod(
           
'selectDatabase',        // The name the XML-RPC Client calls
           
array(&$this, 'selectDatabaseInternal'),    // Pointer to the method, can be a simple string if you have global functions
           
array('dbName', 'something')        // Name of the parameters and their ordering
       
);
    }
   
    public function
selectDatabaseInternal($dbName, $test) {
        return
'dbName:.'.$dbName.'.test:'.$test;
    }
}
?>

Introduction> <SoapVar::SoapVar
Last updated: Fri, 20 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites