DirektiveDesDons/Router/Response.php
2023-01-23 01:08:14 +01:00

48 lines
1013 B
PHP

<?php namespace Router;
class Response
{
/**
* Send a response
* @param string $data
* @param int? $status
* @return void
* @author Johannes Kantz
*/
public function send(string $data, int $status = null)
{
if (isset($status)) {
http_response_code($status);
}
echo $data;
}
/**
* Send a json response
* @param array $data
* @param int? $status
* @return void
* @author Johannes Kantz
*/
public function json(array $data, int $status = null)
{
if (isset($status)) {
http_response_code($status);
}
header('Content-Type: application/json; charset=utf-8');
$data["status"] = http_response_code();
echo json_encode($data);
}
/**
* Set the status code
* @param int $status
* @return void
* @author Johannes Kantz
*/
public function status(int $status)
{
http_response_code($status);
}
}