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->initHandlers(); $action = $_POST['action']; // call the right handler $this->actions[$action](); } else { echo('{data:"error"}'); } } /** * Send response message and exit script * @param $message string the response message */ function commitMessage($message){ echo $message; exit(0); } /** * add the action handlers in this abstract method */ abstract function initHandlers(); }