load_controller('error'); $error_controller->code($code); die(); } /** * Returns HTTP POST information if POST request. * Returns 405 Method Not Allowed if not. * * If $key is specified, returns only that key. otherwise * returns HTTP 400 Bad Request; */ protected function post_data(?string $key = NULL): array|string { // only post requests allowed if ($_SERVER['REQUEST_METHOD'] != 'POST') $this->error(405); // return entire $_POST array if (!$key) return $_POST; if (!isset($_POST[$key])) $this->error(400); return $_POST[$key]; } }