public function handleMethod(RestRequestItem $requestItem) { $token = $requestItem->getToken(); $method = $requestItem->getMethod(); if ($token->isAnonymous() && $method != 'GET') { // Anonymous requests are only allowed to GET data (not create/edit/delete) $response = new ResponseItem(BAD_REQUEST, "[{$method}] not allowed for anonymous users", null); } elseif ($method == 'GET') { $response = $this->handleGet($requestItem); } elseif ($method == 'POST') { $response = $this->handlePost($requestItem); } elseif ($method == 'DELETE') { $response = $this->handleDelete($requestItem); } elseif ($method == 'PUT') { $response = $this->handlePut($requestItem); } else { $response = new ResponseItem(BAD_REQUEST, "Unserviced Http method type", null); } return $response; }
/** * Tests RestRequestItem->getMethod() */ public function testGetMethod() { $this->assertEquals('GET', $this->RestRequestItem->getMethod()); }