XML_RPC_Easy (pre)proposal

From: Date: Sun, 25 Sep 2005 16:11:30 +0000
Subject: XML_RPC_Easy (pre)proposal
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-39926@lists.php.net to get a copy of this message
Hi, I would like to (pre)propose a new package : XML_RPC_Easy ==> Introduction : In very high level languages like Python, web services are really easy to use on the client side like on the server side. SOAP or XMLRPC calls are natural like : client.function('arg1', 'arg2') No need to encode the arguments in XMLRPC stuff, no need to make a XMLRPC message before sending it. No need to decode the XMLRPC response... It's really easy : you just call a method (like it was local). In PHP, a client call with PEAR/XML/RPC/Client is complex : [...] $params = array(new XML_RPC_Value(1, 'int')); $msg = new XML_RPC_Message('release.getRecent', $params); $cli = new XML_RPC_Client('/xmlrpc.php', 'pear.php.net'); $resp = $cli->send($msg); $val = $resp->value(); $data = XML_RPC_decode($val); [...] There is a encoding process, a decoding process. It's really boring when you use a lot of XMLRPC webservices. The server side is as complex. ==> Ideas : - Make a PHP5 only class to be able to use __call catchall for automatic proxy creation... - Automatic encoding and decoding (XML_RPC stuff has to be completly encapsulated) - DO NOT REINVENT THE WHEEL : classes are only parent classes of XML_RPC_Client and XML_RPC_Server ones. ==> Examples (server side) <?php require_once('XML/RPC/Easy/Server.php'); // Dispatch Map $dispatchMap = array( 'ping' => array('function' => 'ping'), 'test' => array('function' => 'test') ); // Classic functions (no XML_RPC stuff here !) function ping() { return 'pong'; } function test($var1, $var2) { return(array($var, array($var1, $var2))); } $xmlrpc = new XML_RPC_Easy_Server($dispatchMap); ?> Easy, isn't it ? ==> Examples (client side) <?php require_once('XML/RPC/Easy/Client.php'); $client = new XML_RPC_Client_Easy('/.../xmlrpc.php', 'host'); if ($client->ping()=='pong') { print_r($client->test('foo','bar')); } ?> Easy, isn't it ? The result is of course : Array ( [0] => foo [1] => Array ( [0] => foo [1] => bar ) ) So, the automatic encoding/decoding process works well even with complex return type. ==> The code : http://fabien.openesub.org/XML_RPC_Easy_Server.txt http://fabien.openesub.org/XML_RPC_Easy_Client.txt Comments are welcome before the formal proposal process. Regards, -- Fabien MARTY fabien.marty@free.fr

« previous php.pear.dev (#39926) next »