## 為什么單獨創建一個Response?
跟`為什么要單獨創建一個Request` 一樣。
原因: 可以管理
如: 在 `swoole` 不應該用 `echo`, 因為 `swoole` 是 `cli` 運行,只會輸出在命令行。
`必須` 只有一個地方能 `輸出響應` 就是此篇的功能
確保有 `集中控制權` 是非常重要 !
(后面代碼有 `echo` 都是不規范的, 應該調用 `此篇` 的功能)
## 創建core/Response.php
```
<?php
namespace core;
class Response
{
protected $headers = []; // 要發送的請求頭
protected $content = ''; // 要發送的內容
protected $code = 200; // 發送狀態碼
public function sendContent() // 發送內容
{
echo $this->content;
}
public function sendHeaders() // 發送請求頭
{
foreach ($this->headers as $key => $header)
header($key.': '.$header);
}
public function send() // 發送
{
$this->sendHeaders();
$this->sendContent();
return $this;
}
public function setContent($content) // 設置內容
{
if( is_array($content))
$content = json_encode($content);
$this->content = $content;
return $this;
}
public function getContent() // 獲取內容
{
return $this->content;
}
public function getStatusCode() // 獲取狀態碼
{
return $this->code;
}
public function setCode(int $code) // 設置狀態碼
{
$this->code = $code;
return $this;
}
}
```
## 在容器綁定Response類
編輯 `app.php`的`register` 方法

## 編輯index.php


- 前言
- 基礎篇
- 1. 第一步 創建框架目錄結構
- 2. 引入composer自動加載
- 3. php自動加載 (解釋篇)
- 4. 創建容器 注冊樹模式
- 5. 關于psr規范解釋
- 6. 關于"容器" "契約" "依賴注入" (解釋篇)
- 7. 添加函數文件helpers.php
- 8. 初始化請求(Request)
- 9. 響應 (Response)
- 10. 路由一 (路由組實現)
- 11. 路由二 (加入中間件)
- 12. 配置信息 (類似laravel)
- 13. 數據庫連接 (多例模式)
- 14. 查詢構造器 (query builder)
- MVC實現
- M 模型實現 (數據映射 + 原型 模式)
- C 控制器實現 + 控制器中間件
- V 視圖實現 (Laravel Blade 引擎)
- V 視圖切換成 ThinkPhp 模板 引擎)
- 其他輪子
- 日志
- 自定義異常 (異常托管)
- 單元測試 (phpunit)
- 替換成swoole的http服務器
- 協程上下文解決request問題
- qps測試
- 發布到packagist.org