yiisoft/friendly-exception 问题修复 & 功能扩展

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

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

yiisoft/friendly-exception

最新稳定版本:1.2.0

Composer 安装命令:

composer require yiisoft/friendly-exception

包简介

An interface for friendlier exception

README 文档

README

Yii

Yii Friendly Exception


Latest Stable Version Total Downloads

An exception interface that provides a friendly name and a possible solution. Error handlers may consider the interface to render additional information right at the error screen.

Example of implementation in Yii Error Handler:

Frendly exception

Requirements

  • PHP 7.4 - 8.5.

Installation

The package could be installed with Composer:

composer require yiisoft/friendly-exception

General usage

Implementing friendly exception

To make exception friendly require this package and implement FriendlyExceptionInterface:

use Yiisoft\FriendlyException\FriendlyExceptionInterface;

class RequestTimeoutException extends \RuntimeException implements FriendlyExceptionInterface
{
    public function getName(): string
    {
        return 'Request timed out.';
    }
    
    public function getSolution(): ?string
    {
        return <<<'SOLUTION'
            Likely it is a result of resource request is not responding in a timely fashion. Try increasing timeout.
            SOLUTION;
    }
}

When returning solution consider the following best practices:

  1. Make solution description as short as possible.
  2. Do not use HTML tags.
  3. Use simple markdown.

Handling friendly exception

To make your exception handler render friendly exceptions:

use Yiisoft\FriendlyException\FriendlyExceptionInterface;

class ThrowableHandler
{
    public function handle(\Throwable $t)
    {
        if ($t instanceof FriendlyExceptionInterface) {
            // additional handling
        }
        // regular handling
    }
}

Do not forget to render markdown.

Documentation

If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.

License

The Yii Friendly Exception is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

统计信息

  • 总下载量: 1.66M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 49
  • 点击次数: 1
  • 依赖项目数: 55
  • 推荐数: 0

GitHub 信息

  • Stars: 49
  • Watchers: 16
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-09-23