peraleks / laravel-pretty-errors
Laravel 错误格式化工具。
v1.0.0
2017-03-31 11:44 UTC
Requires
- php: ^7.0
- laravel/framework: >=5.1
This package is not auto-updated.
Last update: 2024-09-29 02:26:50 UTC
README
LaravelPrettyErrors
Laravel 5.1 或更高版本的错误格式化工具。提供方便的HTML页面和浏览器控制台显示。提供增强的堆栈跟踪视图(查看参数内容:数组,闭包,资源,字符串;以及查看 PHPDoc 类和方法)。提供配置自定义页面 404 和 500 的机会。
安装
$ composer require peraleks/laravel-pretty-errors
使用方法
将文件 vendor/peraleks/laravel-pretty-errors/src/Config/pretty-errors.php 复制到 Laravel 配置路径 (app/config)。
向 App\Exceptions\Handler 添加代码
use Peraleks\LaravelPrettyErrors\Core\PrettyHandler; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; protected function convertExceptionToResponse(Exception $e) { $html = PrettyHandler::format($e, config_path('pretty-errors.php')); $e = FlattenException::create($e); return SymfonyResponse::create($html, $e->getStatusCode(), $e->getHeaders()); }
配置
文件 pretty-errors.php
$development = [ \Peraleks\LaravelPrettyErrors\Notifiers\HtmlNotifier::class => [ 'enabled' => true, // [bool] switch error display as html 'handleTrace' => E_ALL, // [int] switch trace processing (bitwise mask) 'simpleTrace' => true, // [bool] switch display arguments in trace 'hideTrace' => true, // [bool] switch trace display on start 'fontSize' => 15, // [int] main font size in pixels (works as a scale) 'stringLength' => 80, // [int] line length in cells 'tooltipLength' => 1000, // [int] line length in extended view 'arrayLevel' => 2, // [int] nesting level of arrays ], \Peraleks\LaravelPrettyErrors\Notifiers\BrowserConsoleNotifier::class => [ 'enabled' => true, // [bool] switch error display in browser console 'handleTrace' => E_ALL, // [int] switch trace processing (bitwise mask) 'phpNativeTrace' => true, // [bool] switch PHP native trace display 'console' => 'log', // [string] browser console section (error|warn|info|log|debug) ], ]; $production = [ \Peraleks\LaravelPrettyErrors\Notifiers\ProductionNotifier::class => [ 'enabled' => true, // [bool] switch error page display in production 'file404' => '', // [string] fully qualified file name or blade-template name 'file500' => '', // [string] fully qualified file name or blade-template name /* For blade-template, write 'view.404' where '404' is the name for 404.blade.php . You can use native PHP template. To do this, enter the fully qualified file name. The file may not be a template, but must return or print a string. For example, a file can contain such a code: return "<h2>Page not found</h2>"; or echo view('404')->render(); */ ], ];
许可证
MIT 许可证 (MIT)。


