/**
* Uguu
*
- * @copyright Copyright (c) 2022 Go Johansson (nokonoko) <neku@pomf.se>
+ * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/**
* Takes a string as an argument and sets the header to the appropriate content type
*
- * @param $response_type string The type of response you want to return. Valid options are: csv, html, json, text.
+ * @param $response_type string The type of response you want to return.
+ * Valid options are: csv, html, json, text.
*/
public function __construct(string $response_type)
{
default:
header('Content-Type: application/json; charset=UTF-8');
$this->type = 'json';
- $this->error(400, 'Invalid response type. Valid options are: csv, html, json, text.');
break;
}
}
* @param $code mixed The HTTP status code to return.
* @param $desc string The description of the error.
*/
- public function error(mixed $code, string $desc):void
+ public function error(int $code, string $desc):string
{
$response = match ($this->type) {
'csv' => $this->csvError($desc),
};
http_response_code($code);
echo $response;
+ exit(1);
}
/* Returning a string that contains the error message. */
}
/**
- * "If the type is csv, then call the csvSuccess function, if the type is html, then call the htmlSuccess function, etc."
+ * "If the type is csv, then call the csvSuccess function,
+ * if the type is html, then call the htmlSuccess function, etc."
*
* The `match` keyword is a new feature in PHP 8. It's a lot like a switch statement, but it's more powerful
*
}
return $result;
}
- }
+ }
\ No newline at end of file