/** * Set response status * * @param int $responseStatusCode HTTP Status code */ private function setStatus($responseStatusCode = Response::OK_CODE) { $this->addHeader("HTTP/1.1 {$responseStatusCode} " . Response::getStatuses()[$responseStatusCode]); if ($responseStatusCode == self::METHOD_NOT_ALLOWED_CODE) { $this->addHeader("Allow: " . implode(', ', $this->request->getSupportedRequestMethods())); } }
private function deletePost($id) { // Abort request if ID is not present if (empty($id)) { return $this->response->sendJson(Response::BAD_REQUEST_CODE); } // Retrieved post by ID $mapper = new PostMapper($this->container['adapter']); $post = $mapper->findById($id); // If post does not exist, throw not found if (empty($post)) { return $this->response->sendJson(Response::NOT_FOUND_CODE, "No post with such ID is found."); } // Attempt to delete a post if ($mapper->delete($id)) { return $this->response->sendJson(Response::OK_CODE, "Entry is deleted."); } // Deletion fails return $this->response->sendJson(Response::INTERNAL_SERVER_ERROR_CODE); }
/** * @runInSeparateProcess */ public function testResponseObjectReturnsJsonContentType() { $response = new Response($this->container['request']); $response->sendJson(Response::OK_CODE); $this->assertContains('Content-Type: application/json', xdebug_get_headers()); }