// Rest Server Class New Instance
 $restServer = new RestServer();
 //Rest Server starts with a 200 message
 $restServer->setStatus(200);
 //Rest Server Variables
 $resource = $restServer->getResource();
 //Get the Resources
 $verb = $restServer->getVerb();
 //Get the Verb
 $getData = $restServer->getServerData();
 //Get Data
 $id = $restServer->getId();
 //Get ID
 //Get, Put, Post, Delete
 if ($resource === 'corps') {
     $resourceCorps = new Corporations();
     //Corporations New Instance
     $dataResults = null;
     if ($verb === 'GET') {
         if ($id === NULL) {
             $dataResults = $resourceCorps->getAll();
         } else {
             $dataResults = $resourceCorps->get($id);
         }
     }
     if ($verb === 'PUT') {
         if ($id === NULL) {
             throw new InvalidArgumentException('Corporation ID ' . $id . ' was not found');
         } else {
             $dataResults = $resourceCorps->put($getData, $id);
         }
示例#2
0
<?php

include_once './autoload.php';
$restServer = new RestServer();
try {
    $restServer->setStatus(200);
    $resource = $restServer->getResource();
    $verb = $restServer->getVerb();
    $id = $restServer->getId();
    $data = $restServer->getServerData();
    if ('corporations' === $resource) {
        $corps = new Corporations();
        $results = null;
        if ('GET' === $verb) {
            if (is_null($id)) {
                $results = $corps->getAll();
            } else {
                $results = $corps->get($id);
            }
        }
        if ('DELETE' === $verb) {
            if (is_null($id)) {
                throw new InvalidArgumentException('missing ID');
            } else {
                if ($corps->delete($id)) {
                    $restServer->setMessage('Deleted successfully');
                } else {
                    throw new InvalidArgumentException('Delete unsuccessful for id ' . $id);
                }
            }
        }