PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Chris Jeffries   PHP JSON RPC 2.0 Server   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: HTTP shim for server class
Class: PHP JSON RPC 2.0 Server
Handle to HTTP requests in JSON RPC v2.0 format
Author: By
Last change:
Date: 6 years ago
Size: 1,007 bytes
 

Contents

Class file image Download
<?php
   
require_once('jsonrpcServer.class.php');
    try {
       
$s = new jsonrpcServer();
   
        if(!isset(
$_POST['data'])) {
            throw new
Exception("No data supplied in POST 'data' parameter ", 31008);
        }
       
$s->process($_POST['data']);
       
$s->despatch();
    }
    catch (
Exception $e) {
       
$msg = $e->getMessage();
       
$code = $e->getCode();
       
$retval = new stdClass();
       
$retval->error = new stdClass();
       
$filepath = explode('/', $e->getFile());
        if(
file_exists('MaintenanceMode')) {
           
$meth = array_search('methods', $filepath);
            if(
$meth !== false) {
               
$prefix = 'Method: '.$filepath[$meth+1].' - ';
            } else {
               
$serv = array_search('services', $filepath);
               
$prefix = 'Service: '.$filepath[$serv+1].' - ';
            }
           
$suffix = ' (line:'.$e->getLine() . ' in:'.$e->getFile().')';
        } else {
           
$suffix = '';
           
$prefix = '';
        }
       
$retval->error->code = $code;
       
$retval->error->message = $prefix . $msg . $suffix;
       
header('Content-type: application/json');
        echo
json_encode($retval, JSON_PRETTY_PRINT);
    }