PHP Classes

File: rest.php

Recommend this page to a friend!
  Classes of Rafal Przetakowski   PHP REST Server Class   rest.php   Download  
File: rest.php
Role: Example script
Content type: text/plain
Description: Auxiliary script
Class: PHP REST Server Class
REST Web service server that maps URL to API calls
Author: By
Last change: Update of rest.php
Date: 8 months ago
Size: 1,384 bytes
 

Contents

Class file image Download
<?php

/**
 *
 *
 * GNU General Public License (Version 2, June 1991)
 *
 * This program is free software; you can redistribute
 * it and/or modify it under the terms of the GNU
 * General Public License as published by the Free
 * Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * @author Corey Maynard <http://coreymaynard.com/>
 * @author RafaƂ Przetakowski <rafal.p@beeflow.co.uk>
 */
session_start();

function
__autoload($className) {
    if (
file_exists("restObjects/rest_$className.php")) {
        require_once
"restObjects/rest_$className.php";
    } else if (
file_exists("$className.php")) {
        require_once
"$className.php";
    } else {
       
user_error("There is no $className", 'E_ERROR');
    }
}

if (!
array_key_exists('HTTP_ORIGIN', $_SERVER)) {
   
$_SERVER['HTTP_ORIGIN'] = $_SERVER['SERVER_NAME'];
}


try {
   
$API = new restServer($_REQUEST['request'], $_SERVER['HTTP_ORIGIN']);

   
/* register objects */
   
$API->register('User');

   
/* process API */
   
echo $API->processAPI();
} catch (
Exception $e) {
    echo
json_encode(Array('error' => $e->getMessage()));
}

echo
"\n";