if ($verb === 'PUT') {
            if ($id === NULL) {
                throw new InvalidArgumentException('Corporation ID ' . $id . ' was not found');
            } else {
                $dataResults = $resourceCorps->put($getData, $id);
            }
        }
        if ($verb === 'POST') {
            if ($resourceCorps->post($getData)) {
                $restServer->setMessage('New Corporation Information Added');
                $restServer->setStatus(201);
            } else {
                throw new Exception('Corporation could not be added');
            }
        }
        if ($verb === 'DELETE') {
            if ($id === NULL) {
                throw new InvalidArgumentException('Id required');
            } else {
                if ($resourceCorps->delete($id)) {
                    $restServer->setMessage($id . ' Has been deleted');
                }
            }
        }
        $restServer->setData($dataResults);
    }
} catch (Exception $ex) {
    $restServer->setErrors($ex->getMessage());
    $restServer->setStatus(500);
}
$restServer->outputResponse();
Esempio n. 2
0
 $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);
             }
         }
     }
     if ('PUT' === $verb) {
         if (is_null($id)) {
             throw new InvalidArgumentException('missing ID');
         } else {
             $results = $corps->put($data, $id);
         }
     }
     if ('POST' === $verb) {
         if ($corps->post($data)) {