juggl/juggl/services/apiBranch.inc.php

38 lines
1.3 KiB
PHP
Raw Normal View History

2020-01-10 22:33:46 +01:00
<?php
require_once(__DIR__."/authenticator.inc.php");
require_once(__DIR__."/responses.inc.php");
require_once(__DIR__."/requestTypes.inc.php");
require_once(__DIR__."/dbOperations.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) {
if ($authenticationRequired) {
$auth = new Authenticator();
if (!$auth->isAuthenticated($_SESSION, $_REQUEST)) {
$this->authenticationMissing($this->getParams());
return;
}
}
$currentType = currentRequestType();
if($currentType === RequestType::GET) {
$this->get($this->getParams());
} else if ($currentType === RequestType::POST) {
$this->post($this->getParams());
}
}
private function getParams() {
$content = json_decode(file_get_contents('php://input'), true);
$contentArray = array("json" => $content);
return new ParamCleaner(array_merge($contentArray, $_REQUEST, $_SESSION, $_FILES));
}
}
?>