## 简介
anbu (俺不?) 是由 daylerees 开发的一款 laravel 的调试工具。 如果有熟悉 laravel3 的朋友应该知道, 内置的 profiler 就是集成的 anbu 。

最近 daylerees 又开始重新开发 anbu , 重构了界面,并且以模块化的方式增加调试组件,值得一试。
## 安装
在 composer.json
的 require
字段里增加 "daylerees/anbu": "dev-master"
1 2 3 4
| "require": { "laravel/framework": "4.2.*", "daylerees/anbu": "dev-master" }
|
执行 composer update
然后在 config/app.php 中增加 对应的 ServiceProvider
1 2 3 4 5 6 7 8 9
| 'providers' => array( ...
'Illuminate\View\ViewServiceProvider', 'Illuminate\Workbench\WorkbenchServiceProvider',
'Anbu\ProfilerServiceProvider',
),
|
alias 数组中加入 Anbu Facade
1 2 3 4 5
| 'aliases' => array( ...
'Anbu' => 'Anbu\Facades\Anbu' )
|
同时,要配置好对应的 database 连接 因为 anbu 会引入一张表用于存储相关的信息。
至此,anbu 安装完毕。
## 功能
为了更好的看到相关功能,在 route.php
文件中,我们加入以下测试代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| //route.php
Route::get('/', function() { //dump function ad('foo'); ad('3'); ad('30.33'); ad(with(new stdClass)->foo = 'bar'); ad(['name' => 'zhangsan', 'age' => 14]);
//timers Anbu::timers()->start('test'); sleep(1); // Do something interesting. Anbu::timers()->end('test', 'Completed doing something.');
//db query \DB::table('anbu')->get();
//log entries \Log::info('info message'); \Log::info('another message'); \Log::error('wrong message');
return View::make('hello'); });
Route::post('/foo/baz/boo', 'Anbu\\Controller\AssetController@index'); Route::patch('/foo/bar', 'Anbu\\Controller\AssetController@index'); Route::put('/foo/bar', 'Anbu\\Controller\AssetController@index'); Route::delete('/foo', 'Anbu\\Controller\AssetController@index');
|
执行 php -S localhost:8000
打开浏览器,访问 localhost:8000 就可以看到左下角的 anbu
了。

目前提供的功能有
### 路由
可以看到所有的请求以及对应的参数,同时针对不同的 http 请求会用不同的颜色标识,很清晰.

### 请求信息
在这个面板可以看到请求头以及 server 变量

Db Query
这个面板可以看到数据库执行语句以及所用的时间

###Logs
同样用不同的标识表明不同类型的日志

###Debug
用 ad 函数打印的变量都会出现在这里

###Timers
可以通过设定 Timer 来检测一段代码的执行时间

### 请求历史
最后一个是新的功能,主要记录了之前所发生的请求,可以” 重放” 之前的请求,比较实用.

这个库还在开发当中,就目前的功能来说,还是比较全的。
daylerees 的视频说明