DNRoot::sendResponse PHP Method

sendResponse() public method

public sendResponse ( string $status, string $content ) : string
$status string
$content string
return string
    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]);
    }