if ('corps' === $resource) { $corps = new Corps(); $results = null; if ($verb === 'GET') { if ($id === NULL) { $results = $corps->getAll(); } else { $results = $corps->get($id); } } if ($verb === 'PUT') { if ($id === NULL) { throw new InvalidArgumentException('Corporation ID ' . $id . ' was not found'); } else { $results = $corps->put($data, $id); $RestServer->setMessage($id . ' updated'); } } if ($verb === 'POST') { if ($corps->post($data)) { $RestServer->setMessage('Corporation Added'); $RestServer->setStatus(201); } else { throw new Exception('Corporation not added'); } } if ($verb === 'DELETE') { if ($id === NULL) { throw new InvalidArgumentException('No ID'); } else { if ($corps->delete($id)) {
$serverData = $restServer->getServerData(); $config = array('DB_DNS' => 'mysql:host=localhost;port=3306;dbname=PHPAdvClassFall2015', 'DB_USER' => 'root', 'DB_PASSWORD' => ''); $db = new PDO($config['DB_DNS'], $config['DB_USER'], $config['DB_PASSWORD']); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); if ('address' === $resource) { $resourceData = new AddressResoruce(); if ('GET' === $verb) { if (NULL === $id) { $restServer->setData($resourceData->getAll()); } else { $restServer->setData($resourceData->get($id)); } } if ('POST' === $verb) { if ($resourceData->post($serverData)) { $restServer->setMessage('Address Added'); $restServer->setStatus(201); } else { throw new Exception('Address could not be added'); } } if ('PUT' === $verb) { if (NULL === $id) { throw new InvalidArgumentException('Address ID ' . $id . ' was not found'); } } } else { throw new InvalidArgumentException($resource . ' Resource Not Found'); //$response['errors'] = 'Resource Not Found'; //$status = 404; }
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'); } } } $restServer->setData($dataResults);
$serverData = $restServer->getServerData(); $config = array('DB_DNS' => 'mysql:host=localhost;dbname=PHPAdvClassFall2015', 'DB_USER' => 'root', 'DB_PASSWORD' => ''); $db = new PDO($config['DB_DNS'], $config['DB_USER'], $config['DB_PASSWORD']); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); if ('corp' === $resource) { $resourceData = new CorpResource(); if ('GET' === $verb) { if (NULL === $id) { $restServer->setData($resourceData->getAll()); } else { $restServer->setData($resourceData->get($id)); } } if ('POST' === $verb) { if ($resourceData->post($serverData)) { $restServer->setMessage('Corp Added'); $restServer->setStatus(201); } else { throw new Exception('Corp could not be added'); } } if ('PUT' === $verb) { if (NULL === $id) { throw new InvalidArgumentException('Corp ID ' . $id . ' was not found'); } else { if ($resourceData->put($serverData, $id)) { $restServer->setMessage("{$id} Corp Updated"); } else { throw new Exception('Corp could not be updated'); } }
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); if ('corp' === $resource) { $resourceData = new CorporationResource(); if ('GET' === $verb) { if (NULL === $id) { $restServer->setData($resourceData->getAll()); } else { $restServer->setData($resourceData->get($id)); } } if ('DELETE' === $verb) { if (is_null($id)) { throw new InvalidArgumentException('missing ID'); } else { if ($resourceData->delete($id)) { $restServer->setMessage('Deleted successfully'); } else { throw new InvalidArgumentException('Delete unsuccessful for id ' . $id); } } } if ('POST' === $verb) { if ($resourceData->post($serverData)) { $restServer->setMessage('Corporation Added'); $restServer->setStatus(201); } else { throw new Exception('Corporation could not be added'); } } if ('PUT' === $verb) { if (NULL === $id) {
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)) { $restServer->setMessage('Post successful');