histogram: Make histograms crash less
[ninja.git] / application / helpers / json.php
blob0919a3fa24bc72c74dbb02bd8e8ed18af452dac3
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Quickly kill request while serving it(s content) as JSON
4 */
5 class json_Core
7 /**
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');
15 $exit = 0;
16 if($http_status_code > 299) {
17 $exit = 1;
18 header("HTTP/1.0 $http_status_code");
20 echo json_encode($response);
21 exit($exit);
24 /**
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);
34 /**
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);