/** * * Sends back the response according to the required format * * @param array $content The array containing the datas to be sent * * @return null * */ protected final function sendBack(array $content, $status_code = 200, $content_type = 'application/json') { $this->response->status->setCode($status_code); $this->rest->setMimeContentType($content_type); $this->response->content->setType($this->rest->getMimeContentType()); if ($content_type == 'application/json') { // JSON format $content = json_encode($content); $this->response->headers->set('Content-Length', strlen($content)); $this->response->content->set($content); } elseif ($content_type == 'application/pdf' || preg_match('image/', $content_type)) { $this->response->headers->set('Content-Length', $content['data']['size']); $this->response->content->set($content['data']['file']); } else { // default case $this->response->content->set('Unknown format'); } }