-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson.plugin.php
35 lines (28 loc) · 979 Bytes
/
json.plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require_once 'app.php';
class JSON extends Plugin {
private $requestStart;
private $json = array('meta' => array('ok' => false, // Request success
't' => 0), // Request time
'payload' => null); // Payload
// This is all there is to it //////////////////////////////////////
function __construct() {
$this->requestStart = microtime(true);
}
function __destruct() {
$this->json['meta']['t'] = microtime(true) - $this->requestStart;
$errors = isset($this->app) ? $this->app->trace() : null;
if (is_array($errors)) {
$this->json['payload'] = $errors;
} else {
$this->json['meta']['ok'] = true;
}
// Output
header('Content-type: application/json');
echo json_encode($this->json);
}
public function payload($data) {
$this->json['payload'] = $data;
}
}
?>