mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-10-31 03:23:01 +00:00
24 lines
585 B
PHP
24 lines
585 B
PHP
<?php
|
|
|
|
namespace AirQuality;
|
|
|
|
/**
|
|
* Automates the sending of API responses.
|
|
*/
|
|
class ApiResponseSender
|
|
{
|
|
|
|
function __construct() {
|
|
|
|
}
|
|
|
|
public function send_error_plain($code, $message, $extra_headers = []) {
|
|
http_response_code($code);
|
|
header("content-type: text/plain");
|
|
header("content-length: " . strlen($message)); // strlen isn't multibyte-safe, so it'll give us the actual length of the string in bytes, not characters - which is precisely what we want here :D
|
|
foreach($extra_headers as $header)
|
|
header("{$header[0]}: {$header[1]}");
|
|
|
|
echo($message);
|
|
}
|
|
}
|