JsonResponse.php
9 years ago
Request.php
9 years ago
Response.php
8 years ago
Router.php
8 years ago
Response.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\Http; |
| 4 | |
| 5 | |
| 6 | class Response |
| 7 | { |
| 8 | protected $content; |
| 9 | |
| 10 | protected $status; |
| 11 | |
| 12 | protected $headers = array( |
| 13 | 'Content-Type' => 'text/html' |
| 14 | ); |
| 15 | |
| 16 | public function __construct($content, $status = 200) |
| 17 | { |
| 18 | $this->content = $content; |
| 19 | $this->status = $status; |
| 20 | } |
| 21 | |
| 22 | public function render() |
| 23 | { |
| 24 | $this->sendHeaders(); |
| 25 | $this->sendContent(); |
| 26 | die; |
| 27 | } |
| 28 | |
| 29 | protected function sendHeaders() |
| 30 | { |
| 31 | foreach($this->headers as $header => $value) { |
| 32 | header($header.': '.$value); |
| 33 | } |
| 34 | http_response_code($this->status); |
| 35 | } |
| 36 | |
| 37 | protected function sendContent() |
| 38 | { |
| 39 | echo $this->content; |
| 40 | } |
| 41 | } |