## 創建helpers.php

## index.php調用

## 不規范
直接 `include` 雖然可以,但是沒有遵守規范。
`composer` 提供了 `include` 文件方式。
## 遵守規范
編輯 `composer.json`。
```
"files": [
"app/helpers.php"
]
```

執行 `compoer dump-autoload`
## index.php調用

## 補充
將這些函數添加到helpers.php,方便以后寫代碼。
```
<?php
function hello()
{
return "world";
}
if (! function_exists('response')) {
function response()
{
return App::getContainer()->get('response')
return App::getContainer()->getApp('response'); // 這是錯誤的
}
}
function app($name = null)
{
if( $name) // 如果選擇了具體實例
return App::getContainer()->get($name);
return App::getContainer();
}
function endView()
{
$time = microtime(true) - FRAME_START_TIME;
$memory = memory_get_usage() - FRAME_START_MEMORY;
echo '<br/><br/><br/><br/><br/><hr/>';
echo "運行時間: ". round($time * 1000,2) .'ms<br/>';
echo "消耗內存: ". round($memory / 1024 / 1024,2) . 'm';
}
function config($key = null)
{
if( $key)
return App::getContainer()->get('config')->get($key) ;
return App::getContainer()->get('config');
}
```
- 前言
- 基礎篇
- 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