public function sendResponse($status, $content)
{
// strip excessive newlines
$content = preg_replace('/(?:(?:\\r\\n|\\r|\\n)\\s*){2}/s', "\n", $content);
$sendJSON = strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false || $this->getRequest()->getExtension() == 'json';
if (!$sendJSON) {
$this->response->addHeader("Content-type", "text/plain");
return $content;
}
$this->response->addHeader("Content-type", "application/json");
return json_encode(['status' => $status, 'content' => $content]);
}