note 93541 added to book.xmlrpc

From: Date: Tue, 15 Sep 2009 15:07:12 +0000
Subject: note 93541 added to book.xmlrpc
Groups: php.notes 
Request: Send a blank email to php-notes+get-160577@lists.php.net to get a copy of this message
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; } } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 87.51.7.144 ---- Manual Page -- http://www.php.net/manual/en/book.xmlrpc.php Edit -- https://master.php.net/note/edit/93541 Del: integrated -- https://master.php.net/note/delete/93541/integrated Del: useless -- https://master.php.net/note/delete/93541/useless Del: bad code -- https://master.php.net/note/delete/93541/bad+code Del: spam -- https://master.php.net/note/delete/93541/spam Del: non-english -- https://master.php.net/note/delete/93541/non-english Del: in docs -- https://master.php.net/note/delete/93541/in+docs Del: other reasons-- https://master.php.net/note/delete/93541 Reject -- https://master.php.net/note/reject/93541 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160577) next »