47 lines
965 B
PHP
47 lines
965 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');
|
|
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);
|
|
}
|
|
} |