예제 #1
0
 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);
         }
     }
     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)) {
예제 #2
0
        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)) {
                $restServer->setMessage('Post successful');
                $restServer->setStatus(201);
            } else {
                throw new Exception('Post unsuccessful');
            }
        }
        $restServer->setData($results);
    }
} catch (InvalidArgumentException $e) {
    $restServer->setErrors($e->getMessage());
    $restServer->setStatus(400);