note 73371 added to ref.xmlrpc

From: Date: Tue, 20 Feb 2007 16:19:47 +0000
Subject: note 73371 added to ref.xmlrpc
Groups: php.notes 
Request: Send a blank email to php-notes+get-123600@lists.php.net to get a copy of this message
Hi, A little snippet to implement OO XML RPC Server. File RPCPlugin.php : class RPCPlugins { private $plugins; function __construct ($pathname, $rpcServer) { $d = dir($pathname); while (($file = $d->read()) !== false) { if (ereg('(.*)\.php$', $file, $regs)) { include_once ($pathname . '/' . $file); $class=$regs[1]; $this->plugins = new $class($rpcServer); } } } } class RPCPlugin { private $_rpcServer; function __construct($rpcServer) { $this->_rpcServer = $rpcServer; $methods = get_class_methods($this); foreach ($methods as $method) { if (substr($method, 0,1) != '_') { xmlrpc_server_register_method($rpcServer,get_class($this) . "." . $method,array(&$this,$method)); } } } } An example of plugin in plugins/Test.php : class Test extends RPCPlugin { function HelloWorld ($method, $params) { return "Hello World --->>" . $params[0]; } } Now the real server : require_once 'RPCPlugin.php'; $rpcServer = xmlrpc_server_create(); $plugins = new RPCPlugins(realpath('plugins/'), $rpcServer); $resp = xmlrpc_server_call_method($rpcServer,$HTTP_RAW_POST_DATA,null); if ($resp) { header ('Content-Type: text/xml'); echo $resp; } xmlrpc_server_destroy($rpcServer) Then you can call ethod by classname.method. For this sample Test.HelloWorld Hn'Co ---- Server IP: 217.174.196.197 Probable Submitter: 81.56.150.194 ---- Manual Page -- http://www.php.net/manual/en/ref.xmlrpc.php Edit -- https://master.php.net/note/edit/73371 Del: integrated -- https://master.php.net/note/delete/73371/integrated Del: useless -- https://master.php.net/note/delete/73371/useless Del: bad code -- https://master.php.net/note/delete/73371/bad+code Del: spam -- https://master.php.net/note/delete/73371/spam Del: non-english -- https://master.php.net/note/delete/73371/non-english Del: in docs -- https://master.php.net/note/delete/73371/in+docs Del: other reasons-- https://master.php.net/note/delete/73371 Reject -- https://master.php.net/note/reject/73371 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123600) next »