diff --git a/src/api.php b/src/api.php index f0430d7..d803212 100644 --- a/src/api.php +++ b/src/api.php @@ -184,67 +184,3 @@ function haveWriteAccess(?int $listId = null) : bool } return true; } - - -class ApiRequest -{ - public $path; - public $method; - public $contentType; - public $jsonBody; - - function __construct() { - $this->path = $_SERVER['PATH_INFO'] ?? ''; - $this->method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET'; - $this->contentType = $_SERVER['CONTENT_TYPE'] ?? ''; - } - - function decodeJsonBody() { - $this->jsonBody = json_decode( file_get_contents('php://input'), true, 10, JSON_INVALID_UTF8_SUBSTITUTE ); - return $this->jsonBody; - } -} - -class ApiResponse -{ - public $data = null; - public $contentType = 'application/json'; - public $code = null; - - function htmlContent(string $content, int $code = 200): ApiResponse - { - $this->contentType = 'text/html'; - $this->data = $content; - $this->code = $code; - return $this; - } - - function exit() - { - if (is_null($this->data) && is_null($this->code)) { - http_response_code(404); - } - if (!is_null($this->code)) { - http_response_code($this->code); - } - if ($this->contentType == 'text/html') { - print $this->data; - exit(); - } - jsonExit($this->data); - } -} - -abstract class ApiController -{ - /** @var ApiRequest */ - protected $req; - - /** @var ApiResponse */ - protected $response; - - function __construct(ApiRequest $req, ApiResponse $response) { - $this->req = $req; - $this->response = $response; - } -} diff --git a/src/includes/common_classes.php b/src/includes/common_classes.php new file mode 100644 index 0000000..5fb36dd --- /dev/null +++ b/src/includes/common_classes.php @@ -0,0 +1,70 @@ + + Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details. +*/ + +class ApiRequest +{ + public $path; + public $method; + public $contentType; + public $jsonBody; + + function __construct() { + $this->path = $_SERVER['PATH_INFO'] ?? ''; + $this->method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET'; + $this->contentType = $_SERVER['CONTENT_TYPE'] ?? ''; + } + + function decodeJsonBody() { + $this->jsonBody = json_decode( file_get_contents('php://input'), true, 10, JSON_INVALID_UTF8_SUBSTITUTE ); + return $this->jsonBody; + } +} + +class ApiResponse +{ + public $data = null; + public $contentType = 'application/json'; + public $code = null; + + function htmlContent(string $content, int $code = 200): ApiResponse + { + $this->contentType = 'text/html'; + $this->data = $content; + $this->code = $code; + return $this; + } + + function exit() + { + if (is_null($this->data) && is_null($this->code)) { + http_response_code(404); + } + if (!is_null($this->code)) { + http_response_code($this->code); + } + if ($this->contentType == 'text/html') { + print $this->data; + exit(); + } + jsonExit($this->data); + } +} + +abstract class ApiController +{ + /** @var ApiRequest */ + protected $req; + + /** @var ApiResponse */ + protected $response; + + function __construct(ApiRequest $req, ApiResponse $response) { + $this->req = $req; + $this->response = $response; + } +} diff --git a/src/includes/notifications.php b/src/includes/notifications.php index 86f5ca8..7c86eb6 100644 --- a/src/includes/notifications.php +++ b/src/includes/notifications.php @@ -1,5 +1,11 @@ + Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details. +*/ + class MTTNotificationCenter { /** diff --git a/src/init.php b/src/init.php index e3e7ba5..09a8339 100644 --- a/src/init.php +++ b/src/init.php @@ -25,6 +25,7 @@ else { } require_once(MTTINC. 'common.php'); +require_once(MTTINC. 'common_classes.php'); require_once(MTTINC. 'version.php'); require_once(MTTINC. 'class.dbconnection.php'); require_once(MTTINC. 'class.dbcore.php');