cerbero/exception-handler
Composer 安装命令:
composer require cerbero/exception-handler
包简介
Extend Laravel exception handler to define how to handle custom exceptions via service providers.
README 文档
README
This Laravel package lets you define the behavior of your application when a specific exception is thrown.
Laravel handles exceptions in app/Exceptions/Handler.php by default, but the more handlers you add the more this class gets cluttered and difficult to read and maintain.
Furthermore it is not possible for an external Laravel package to automatically register how its custom exceptions should be handled by the application where it has been installed.
This package lets you register custom exception handlers by using service providers, so that also external packages may register their own.
Please note: this package leverages the decorators design pattern, which allows you to keep using the Laravel default handler as you normally would. It just wraps the exception handler to extend its functionalities.
Install
Via Composer
composer require cerbero/exception-handler
If your Laravel version is prior to 5.5, please add this service provider in config/app.php
'providers' => [ ... Cerbero\ExceptionHandler\Providers\ExceptionHandlerServiceProvider::class, ]
Usage
There are 3 types of handlers that can be registered:
- Reporters, they log an exception or report it to an external service (e.g. Sentry, Bugsnag...)
- Renderers, they render an exception into an HTTP response
- Console Renderers, they render an exception to the console
The following examples show how to register each type of handler in the boot() method of a service provider:
use App\Exceptions\DebugException; use App\Exceptions\ArtisanException; use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Contracts\Validation\ValidationException; ... public function boot() { // register a custom reporter to log all exceptions that are instances of - or extend - DebugException $this->app->make(ExceptionHandler::class)->reporter(function (DebugException $e) { $this->app['log']->debug($e->getMessage()); }); // register a custom renderer to redirect the user back and show validation errors $this->app->make(ExceptionHandler::class)->renderer(function (ValidationException $e, $request) { return back()->withInput()->withErrors($e->errors()); }); // register a custom console renderer to display errors to the console and stop the propagation of other exceptions $this->app->make(ExceptionHandler::class)->consoleRenderer(function (ArtisanException $e, $output) { $output->writeln('<error>' . $e->getMessage() . '</error>'); return true; }); }
A handler is basically a callback that accepts the exception to handle as first parameter. You can register a global handler by omitting the exception type or type-hinting Exception.
Unlike reporters, renderers also accept a second parameter: an instance of Illuminate\Http\Request in case of a renderer or a Symfony\Component\Console\Output\OutputInterface in case of a console renderer.
It is also important to note that all registered handlers for an exception will be called until one of them returns a truthy value, in that case the exceptions propagation stops.
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email andrea.marco.sartori@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
cerbero/exception-handler 适用场景与选型建议
cerbero/exception-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.7k 次下载、GitHub Stars 达 59, 最近一次更新时间为 2016 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「exceptions」 「laravel」 「exception-handler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cerbero/exception-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cerbero/exception-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cerbero/exception-handler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
php7ify is a project that brings new php7 classes and exceptions to php 5.x.
The CodenamePHP Platform core that contains basic interfaces, exceptions etc..
A simple package to better handle Exceptions.
Laravel client package for FizWatch error tracking
Lightweight error monitoring for Laravel — captures PHP exceptions with full stack traces, code context, breadcrumbs, and sends them to Oopsy. Two-line setup, zero config.
Kanbino Bug Tracking SDK for Laravel - Error capture, breadcrumbs, and session replay
统计信息
- 总下载量: 7.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 59
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-14