classify videoload and Tag requests

This commit is contained in:
2020-07-31 01:03:51 +02:00
parent fd9a54209d
commit a2385e8e4c
4 changed files with 100 additions and 80 deletions

View File

@ -1,24 +1,41 @@
<?php
require 'Database.php';
require_once 'Database.php';
abstract class RequestBase {
private array $actions = array();
protected mysqli $conn;
abstract function initIdentifiers();
/**
* add the action handlers in this abstract method
*/
abstract function initHandlers();
function addIdentifier($action, $callback) {
/**
* adds a new action handler to the current api file
*
* @param $action string name of the action variable
* @param $callback Closure callback function to be called
*/
function addActionHandler($action, $callback) {
$this->actions[$action] = $callback;
}
/**
* runs the correct handler
* should be called once within the api request
*/
function handleAction() {
$this->conn = Database::getInstance()->getConnection();
if (isset($_POST['action'])) {
$this->initIdentifiers();
$this->initHandlers();
$action = $_POST['action'];
call_user_func($this->actions[$action]);
// call the right handler
$this->actions[$action]();
} else {
echo('{data:"error"}');
}
}
}