. namespace hoplite\http2; require_once HOPLITE_ROOT . '/http/response_code.php'; class Response { /*! @var integer The HTTP response code to return. */ public $code; /*! @var array A map of headers to values to be sent with the response. */ public $headers = []; public function __construct($code=\hoplite\http\ResponseCode::OK) { $this->code = $code; } /*! @var string Raw HTTP response body. */ public function generate() { http_response_code($this->code); foreach ($this->headers as $header => $value) { header("$header: $value"); } } } class NotFoundResponse extends Response { public function __construct() { parent::__construct(\hoplite\http\ResponseCode::NOT_FOUND); } public function generate() { parent::generate(); print '

404 - Not Found

'; } } class TextResponse extends Response { private $text; public function __construct($text) { parent::__construct(); $this->text = $text; $this->headers['Content-Type'] = 'text/plain'; } public function generate() { parent::generate(); print $this->text; } }