app = $app; } /** * Method to close the application. * * @param integer $code The HTTP status code. * @param mixed $buffer An optional string to display. * * @return void */ public function close($code = 200, $buffer = null) { // force HTTP status code $this->app->setHeader('status', $code, $replace = true); $this->app->sendHeaders(); if (VBOPlatformDetection::isWordPress() && !headers_sent()) { // this is necessary for the HTTP2 protocol http_response_code($code); } if ($buffer) { // display buffer echo $buffer; } // terminate session $this->app->close(); } /** * Echoes the given JSON by using the right content type. * * @param mixed $json Either a JSON string or a non-scalar value. * @param int $flags Bitmask for json_encode(). * * @return void */ public function json($json, $flags = 0) { $this->app->setHeader('Content-Type', 'application/json', $replace = true); if (!is_string($json)) { // stringify array/object $json = json_encode($json, $flags); } // terminate session by echoing the given JSON $this->close(200, $json); } }