<?php require 'class-jsonrpc.php';
/** * hello world service * @param string $name * @return string */ function hello($name=null){ return 'Hello '.($name?$name:'world'); }
function giveMeAnError(){ throw new jsonRpcMethodException('this is an error'); }
class greatings{ static public function hi($name=null){ return 'Hi '.($name?$name:'world'); } static public function morning($name=null){ return 'Good morning '.($name?$name:'world'); } static public function everyone(array $name=null){ if($name){ $name=implode(', ',$name); } return array('hi'=>self::hi($name),'morning'=>self::morning($name)); } static public function all($name){ return array('hi'=>self::hi($name),'morning'=>self::morning($name)); } function time(){ return 'it is '.date('H\Hi',time()); } }
$jsonService = new jsonRPC();
$jsonService->bindMethod(array('hello','giveError'=>'giveMeAnError')); $jsonService->bindClass('greatings'); $jsonService->bindClass(new greatings());
$jsonService->response($jsonService->processRequest());
|