new class based syntax for handling api requests in php
This commit is contained in:
24
api/RequestBase.php
Normal file
24
api/RequestBase.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
require 'Database.php';
|
||||
|
||||
abstract class RequestBase {
|
||||
private array $actions = array();
|
||||
protected mysqli $conn;
|
||||
|
||||
abstract function initIdentifiers();
|
||||
|
||||
function addIdentifier($action, $callback) {
|
||||
$this->actions[$action] = $callback;
|
||||
}
|
||||
|
||||
function handleAction() {
|
||||
$this->conn = Database::getInstance()->getConnection();
|
||||
|
||||
if (isset($_POST['action'])) {
|
||||
$this->initIdentifiers();
|
||||
|
||||
$action = $_POST['action'];
|
||||
call_user_func($this->actions[$action]);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user