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)) { $restServer->setMessage($id . ' Has been deleted'); } } }
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); } catch (Exception $e) { $restServer->setErrors($e->getMessage()); $restServer->setStatus(500); }