1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
3 * Quickly kill request while serving it(s content) as JSON
8 * Kills the request after echoing a structured json response
10 * @param array $response = null
11 * @param int $http_status_code = 0
13 private static function _send_response($response = null, $http_status_code = 200) {
14 header('Content-Type: application/json');
16 if($http_status_code > 299) {
18 header("HTTP/1.0 $http_status_code");
20 echo json_encode($response);
25 * Give it anything, it will turn it into JSON
27 * @param $reason string
28 * @param $http_status_code int = 500
30 public static function fail($reason = null, $http_status_code = 500) {
31 return self
::_send_response($reason, $http_status_code);
35 * Give it anything, it will turn it into JSON
37 * @param $result string
38 * @param $http_status_code int = 200
40 public static function ok($result = null, $http_status_code = 200) {
41 return self
::_send_response($result, $http_status_code);