diff --git a/flight/Flight.php b/flight/Flight.php index 086df8b..623f693 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -451,9 +451,9 @@ class Flight { * Stops the framework and outputs the current response. */ public static function _stop() { - self::response()-> - write(ob_get_clean())-> - send(); + self::response() + ->write(ob_get_clean()) + ->send(); } /** @@ -463,11 +463,11 @@ class Flight { * @param int $msg Response text */ public static function _halt($code = 200, $text = '') { - self::response(false)-> - status($code)-> - write($text)-> - cache(false)-> - send(); + self::response(false) + ->status($code) + ->write($text) + ->cache(false) + ->send(); } /** @@ -476,28 +476,28 @@ class Flight { * @param object $ex Exception */ public static function _error(Exception $e) { - self::response(false)-> - status(500)-> - write( + self::response(false) + ->status(500) + ->write( '

500 Internal Server Error

'. '

'.$e->getMessage().'

'. '
'.$e->getTraceAsString().'
' - )-> - send(); + ) + ->send(); } /** * Sends an HTTP 404 response when a URL is not found. */ public static function _notFound() { - self::response(false)-> - status(404)-> - write( + self::response(false) + ->status(404) + ->write( '

404 Not Found

'. '

The page you have requested could not be found.

'. str_repeat(' ', 512) - )-> - send(); + ) + ->send(); } /** @@ -506,11 +506,11 @@ class Flight { * @param string $url URL */ public static function _redirect($url, $code = 303) { - self::response(false)-> - status($code)-> - header('Location', $url)-> - write($url)-> - send(); + self::response(false) + ->status($code) + ->header('Location', $url) + ->write($url) + ->send(); } /** @@ -557,6 +557,19 @@ class Flight { self::halt(304); } } + + /** + * Sends a JSON response. + * + * @param mixed $data Data to JSON encode + */ + public static function _json($data) { + self::response(false) + ->status(200) + ->header('Content-Type', 'application/json') + ->write(json_encode($data)) + ->send(); + } } // Initialize framework on include