blob: 9b606be740760309f491b4c8745bca0608824f0a [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2class api {
3 public static function inputJson() {
4 $string = trim(file_get_contents("php://input"));
5
6 if (empty($string)) return false;
7
8 $json = json_decode($string, true);
9
10 if (json_last_error() !== JSON_ERROR_NONE) return false;
11
12 return $json;
13 }
14
15 public static function error($message = null) {
16 if ($message !== null) self::write([
17 'error' => true,
18 'message' => $message,
19 ]);
20 http_response_code(400);
21 exit();
22 }
23
24 public static function write($array) {
25 header('Content-Type: application/json');
26 echo json_encode($array);
27 }
28}