new class based syntax for handling api requests in php
This commit is contained in:
1 parent
d3c3ee3044
commit
fd9a54209d
2 files changed
+42
-18
No files matched your search
@@ -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