定制 phphd/exception-toolkit 二次开发

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

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

phphd/exception-toolkit

最新稳定版本:1.2.0

Composer 安装命令:

composer require phphd/exception-toolkit

包简介

Exception processing toolkit

README 文档

README

🧰 Provides a set of tools to handle exceptions in PHP applications.

Build Status Codecov Packagist Downloads Licence

Installation 📥

  1. Install via composer:

    composer require phphd/exception-toolkit
  2. If you are using Symfony, enable the bundle in the bundles.php

    PhPhD\ExceptionToolkit\Bundle\PhdExceptionToolkitBundle::class => ['all' => true],

Provided tools ⚙️

Exception Unwrapper

Allows you to unwrap composite exceptions and get the atomic errors you are interested in:

use PhPhD\ExceptionToolkit\Unwrapper\ExceptionUnwrapper;

/** @var ExceptionUnwrapper $unwrapper */

$compositeException = new CompositeException([
    new InvalidEmailException(),
    new CompositeException([
        new InvalidPasswordException(),
    ]),
]);

[$emailError, $passwordError] = $unwrapper->unwrap($compositeException);

In this example, errors were retrieved from composite exceptions: $emailError will be an instance of InvalidEmailException and $passwordError will be an instance of InvalidPasswordException that were wrapped in the composite exception.

Symfony integration

In symfony application you could use ExceptionUnwrapper service:

public function __construct(
    #[Autowire('@phd_exception_toolkit.exception_unwrapper')] 
    private ExceptionUnwrapper $exceptionUnwrapper,
) {}

This will provide you with full stack of defined unwrappers bundled into a single instance.

If you want to define custom unwrapper, you should decorate phd_exception_toolkit.exception_unwrapper.stack service.

Built-in unwrappers

Messenger

If you are using symfony messenger, Symfony\Component\Messenger\Exception\WrappedExceptionsInterface will be unwrapped automatically.

Amp

If you are using Amp, Amp\CompositeException will be unwrapped automatically.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-31