juggl/juggl-server/api/services/apiBranch.inc.php
2020-11-08 15:21:51 +01:00

38 lines
No EOL
1.2 KiB
PHP

<?php
require_once(__DIR__."/authenticator.inc.php");
require_once(__DIR__."/responses.inc.php");
require_once(__DIR__."/requestTypes.inc.php");
require_once(__DIR__."/paramCleaner.inc.php");
abstract class ApiBranch {
function get (ParamCleaner $params) {}
function post (ParamCleaner $params) {}
function authenticationMissing (ParamCleaner $params) {
respondStatus(403);
}
function execute ($authenticationRequired = true) {
$params = $this->getParams();
if ($authenticationRequired) {
$auth = new Authenticator();
if (!$auth->isAuthenticated($params)) {
$this->authenticationMissing($params);
return;
}
}
$currentType = currentRequestType();
if($currentType === RequestType::GET) {
$this->get($params);
} else if ($currentType === RequestType::POST) {
$this->post($params);
}
}
private function getParams() {
$content = json_decode(file_get_contents('php://input'), true);
return new ParamCleaner(array_merge($content, $_REQUEST, $_SESSION, $_FILES));
}
}
?>