scottsmith/error-handler 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

scottsmith/error-handler

Composer 安装命令:

composer require scottsmith/error-handler

包简介

Error/Exception handler

README 文档

README

Installation

composer require scottsmith/error-handler

Configuration

There are two main things to set to make the reporter work.

  • The reporter
  • Use the base handler

Reporter

There are two supported reporters:

  • NullReporter
  • LaravelBugsnagReporter

The BugsnagReporter extends the AbstractReporter. This allows to extend the metadata:

$reporter->registerMetaGenerator(new class implements MetaGeneratorInterface {
    public function generateMetaData(): array
    {
        return ['some' => 'data'];
    }
}

Laravel Integration

Configuration

You need to publish the configuration using php artisan vendor:publish.

This allows to update the reporter the ModuleServiceProvider binds as ReporterInterface.

To use the bugsnag reporter you need to install and setup the bugsnag/bugsnag-laravel package.

The app\Exceptions\Handler.php needs to extend the ScottSmith\ErrorHandler\Integration\Laravel\Handler class.

By default, the reporter to be used is the ScottSmith\ErrorHandler\Reporter\NullReporter. To update the reported, simply update the published config config\error-handler.php:

    'reporter' => \ScottSmith\ErrorHandler\Reporter\LaravelBugsnagReporter::class,

If the reporter extends AbstractReporter then you can extend the global data inside your Provider:

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->extend(\ScottSmith\ErrorHandler\Reporter\AbstractReporter::class, function($reporter) {
            $reporter->registerMetaGenerator(new class implements MetaGeneratorInterface {
                public function generateMetaData(): array
                {
                    return ['some' => 'data'];
                }
            }
        });
    }
}

Laminas/Mezzio Integration

Configuration

If you are using the laminas-component-installer the module ConfigProvider should be added automatically. If not then you will have to add the ScottSmith\ErrorHandler\Integration\Mezzio\ConfigProvider manually. eg. config.php

$aggregator = new ConfigAggregator(
    [
        \ScottSmith\ErrorHandler\Integration\Laminas\ConfigProvider::class
        ...
    ]
);

You will then need to create configuration for the service manager. This README only covers the laminas service-manager. Create a file named config\autoload\error.global.php

<?php
use Mezzio\Middleware\ErrorResponseGenerator;
use ScottSmith\ErrorHandler\Integration\Laminas\ErrorResponseGeneratorFactory;

return [
    'dependencies' => [
        'factories' => [
            ErrorResponseGenerator::class => ErrorResponseGeneratorFactory::class,
        ],
    ],
    
    'error_handler' => [
        // Is the application in debug mode
        'debug' => false,

        // Which reporter to use
        'reporter' => \ScottSmith\ErrorHandler\Reporter\LoggerReporter::class,
        
        // The templates to use if you have initialized templating with Mezzio\Template\TemplateRendererInterface 
        'template_404'   => 'error::404',
        'template_error' => 'error::error',
    ],
];

If the reporter extends AbstractReporter then you can extend the global data inside your Provider:

<?php
use Mezzio\Middleware\ErrorResponseGenerator;
use ScottSmith\ErrorHandler\Integration\Laminas\ErrorResponseGeneratorFactory;

return [
    'dependencies' => [
        'initializers' => [
            function(ContainerInterface $container, $instance) {
                if (!$instance instanceof \ScottSmith\ErrorHandler\Reporter\AbstractReporter) {
                    return;
                }
                
                $instance->registerMetaGenerator(new class implements MetaGeneratorInterface {
                    public function generateMetaData(): array
                    {
                        return ['some' => 'data'];
                    }
                }
            }
        ]
    ],
];

scottsmith/error-handler 适用场景与选型建议

scottsmith/error-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 582 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 scottsmith/error-handler 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-12