Login   Register  
PHP Classes
elePHPant
Icontem

File: hello.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jonathan Gotti  >  JSON RPC  >  hello.php  >  Download  
File: hello.php
Role: Example script
Content type: text/plain
Description: sample jsonrpc service
Class: JSON RPC
Handle calls to JSON RPC Web services
Author: By
Last change:
Date: 3 years ago
Size: 1,040 bytes
 

Contents

Class file image Download
<?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());