定制 designcise/bitframe-whoops 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

designcise/bitframe-whoops

Composer 安装命令:

composer require designcise/bitframe-whoops

包简介

Whoops error handler middleware

README 文档

README

CI Maintainability Test Coverage

Whoops error handler middleware to handle application or middleware specific errors.

Installation

$ composer require "designcise/bitframe-whoops"

Please note that this package requires PHP 8.2.0 or newer.

Quickstart

Instantiating

The constructor has the following signature:

new ErrorHandler(
    ResponseFactoryInterface,
    HandlerProviderNegotiator::class,
    [options],
);
  1. The first argument to the constructor must be an instance of Psr\Http\Message\ResponseFactoryInterface;
  2. The second argument to the constructor must be an implementation of \BitFrame\Whoops\Provider\ProviderInterface;
  3. The third argument to the constructor is an optional array of options to specify the following:
    1. catchGlobalErrors: When set to true errors will be handled outside of current batch of middleware set.
    2. Other options are simply method names in Whoops\Handler\*Handler.php and BitFrame\Whoops\Handler\*Handler.php. For example, to set Whoops\Handler\JsonResponseHandler::setJsonApi() you would pass in: ['setJsonApi' => false], etc.

As a shortcut, you can also use the static method ErrorHandler::fromNegotiator($factory, $options). This would use the \BitFrame\Whoops\Provider\HandlerProviderNegotiator by default.

How to Run the Middleware

To run the middleware, simply pass in a BitFrame\Whoops\ErrorHandler instance to your middleware runner / dispatcher.

For example, to handle middleware-specific errors with BitFrame\App (or other PSR-15 dispatchers) it would look something like this:

use BitFrame\App;
use BitFrame\Emitter\SapiEmitter;
use BitFrame\Whoops\ErrorHandler;
use BitFrame\Whoops\Provider\HandlerProviderNegotiator;
use BitFrame\Factory\HttpFactory;

$app = new App();

$middleware = function () {
    throw new \Exception('hello world!');
};

$app->use([
    SapiEmitter::class,
    new ErrorHandler(HttpFactory::getFactory(), HandlerProviderNegotiator::class, [
        'addTraceToOutput' => true,
        'setJsonApi' => false,
    ]),
    $middleware,
]);

$app->run();

To handle global errors with BitFrame\App (or other PSR-15 dispatchers) it would look something like this:

use BitFrame\App;
use BitFrame\Whoops\ErrorHandler;
use BitFrame\Factory\HttpFactory;

$app = new App();

$app->run([
    ErrorHandler::fromNegotiator(HttpFactory::getFactory(), [
        'catchGlobalErrors' => true,
        'addTraceToOutput' => true,
        'setJsonApi' => false,
    ]),
]);

throw new \Exception('hello world!');

How Does It Work?

The error handler middleware automatically determines the error handler to use based on the Accept header. The following error handler providers are included:

  1. BitFrame\Whoops\Provider\HtmlHandlerProvider for Whoops\Handler\PrettyPageHandler;
  2. BitFrame\Whoops\Provider\JsonHandlerProvider for Whoops\Handler\JsonResponseHandler;
  3. BitFrame\Whoops\Provider\JsonpHandlerProvider for BitFrame\Whoops\Handler\JsonpResponseHandler;
  4. BitFrame\Whoops\Provider\TextHandlerProvider for Whoops\Handler\PlainTextHandler;
  5. BitFrame\Whoops\Provider\XmlHandlerProvider for Whoops\Handler\XmlResponseHandler;

Tests

To run the tests you can use the following commands:

Command Type
composer test PHPUnit tests
composer style CodeSniffer
composer md MessDetector
composer check PHPStan

Contributing

Documentation

Complete documentation for v3 will be available soon.

License

Please see License File for licensing information.

designcise/bitframe-whoops 适用场景与选型建议

designcise/bitframe-whoops 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 119 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 designcise/bitframe-whoops 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 designcise/bitframe-whoops 我们能提供哪些服务?
定制开发 / 二次开发

基于 designcise/bitframe-whoops 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 119
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-05