laravel 从Debugbar开始

1.创建laravel项目

先添加国内镜像

composer config -g repo.packagist composer https://packagist.phpcomposer.com

进到项目目录执行如下命令

composer create-project laravel/laravel --prefer-dist obj_laravel
2.php启动laravel站点
php -S localhost:80 -t obj_laravel/public

相关操作命令

#创建控制器
php artisan make:controller MyController
php artisan make:controller PhotoController --resource

#显示路由
php artisan route:list

#生成模型
php artisan make:model User

#数据迁移
php artisan make:migration create_users_table

#运行迁移
php artisan migrate

#数据填充
php artisan make:seeder UserTableSeeder

#运行填充器
php artisan db:seedphp artisan db:seed --class=UserTableSeeder

#回滚并重新运行迁移
php artisan migrate:refresh --seed

Debugbar

1.使用compser引入package
composer require barryvdh/laravel-debugbar
2.config/app.php的providers中添加注册服务
#line:124~160左右
Barryvdh\Debugbar\ServiceProvider::class,
3.门面(可选)
#config/app.php中添加如下门面别名到 aliases数组:
'Debugbar' => Barryvdh\Debugbar\Facade::class,

#然后运行如下 Artisan 命令将该扩展包的配置文件拷贝到 config目录下:
php artisan vendor:publish
如果配置文件中 debug设置为 true的话,Debugbar 分析器默认是启的,如果你想要关闭该分析器,在配置文件 config/debugbar.php中设置 enab为 false即可。

使用 Debugbar 门面添加 PSR-3 级别消息:
Debugbar::info($object);Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');
设置开始/中止时间:
Debugbar::startMeasure('render','Time for rendering');
Debugbar::stopMeasure('render');
Debugbar::addMeasure('now', LARAVEL_START, microtime(true));
Debugbar::measure('My long operation', function() { // Do something…});
记录异常:
try {
   throw new Exception('foobar');
} catch (Exception $e) { 
    Debugbar::addException($e);
}
使用辅助函数实现上述调用:
// All arguments will be dumped as a debug message
debug($var1, $someString, $intValue, $object);
start_measure('render','Time for rendering');
stop_measure('render');
add_measure('now', LARAVEL_START, microtime(true));
measure('My long operation', function() { 
    // Do something…
});
如果想要添加自己的数据收集器(DataCollector),可以通过容器或门面实现:
Debugbar::addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages'));
或者通过 App 容器:
$debugbar = App::make('debugbar');
$debugbar->addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages'));
默认情况下,Debugbar 被注入到 </body>之前。如果你想要自己注入 Debugbar,在其配置文件中设置 inject为 false然后使用渲染器自己渲染:
$renderer = Debugbar::getJavascriptRenderer();

注意:使用自动注入的话将会禁止显示 Request 信息,因为在响应之后才会添加该信息。你可以通过在配置文件中添加 default_request数据收集器作为替换方案。

如果你想要在运行时开启/关闭 Debugbar,可以通过如下方式:
\Debugbar::enable();\Debugbar::disable();
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,049评论 19 139
  • 原文链接 必备品 文档:Documentation API:API Reference 视频:Laracasts ...
    layjoy阅读 8,640评论 0 121
  • 先说几句废话,调和气氛。事情的起由来自客户需求频繁变更,伟大的师傅决定横刀立马的改革使用新的框架(created ...
    wsdadan阅读 3,112评论 0 12
  • 必备品文档:DocumentationAPI: API Reference视频:Laracasts速查表:Lara...
    ethanzhang阅读 5,798评论 0 68
  • 文/朕梁栋 我在院子里劈柴 碗口粗的柴禾竖放在地上 我举起斧子,我落下斧子 我放下斧子,我再举起斧子 一根柴变成了...
    朕梁栋阅读 786评论 9 3