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"}'); } } }