DirektiveDesDons/Router/Response.php

44 lines
875 B
PHP
Raw Normal View History

2022-12-08 14:43:05 +01:00
<?php namespace Router;
class Response
{
/**
* Send a response
* @param string $data
* @param int? $status
* @return void
*/
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
*/
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
*/
public function status(int $status)
{
http_response_code($status);
}
}