定制 temant-framework/temant-fault 二次开发

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

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

temant-framework/temant-fault

Composer 安装命令:

composer require temant-framework/temant-fault

包简介

A modern, feature-rich exception handler for PHP with HTML, JSON, XML, and plain text rendering. Part of the Temant Framework.

README 文档

README

Temant Fault

A modern, feature-rich exception handler for PHP.

CI Coverage Latest Version Total Downloads PHP Version License PHPStan Level 9

Fault is an exception handler that catches uncaught exceptions and PHP errors, then renders beautiful, information-rich error pages. It supports HTML, JSON, XML, and plain text output with automatic content negotiation. Part of the Temant Framework.

Features

  • Interactive HTML error page with syntax-highlighted source code
  • Stack trace sidebar with frame filtering and keyboard navigation
  • Tabbed debug panels: Request, Environment, Session, Cookies, Logs, Git, Xdebug
  • JSON, XML, and plain text renderers for APIs and CLI
  • Automatic content negotiation via HTTP Accept header
  • Light/dark theme with localStorage persistence
  • "Open in editor" links (PHPStorm, VS Code, Sublime, Atom, IntelliJ, NetBeans)
  • Sensitive data masking (passwords, API keys, tokens)
  • Exception chain support with full previous-exception rendering
  • Listener callbacks for logging and external error reporting
  • Production mode with safe, detail-free error pages
  • PHPStan level 9 strict typing

Requirements

  • PHP 8.2 or higher
  • Extensions: json, mbstring, xmlwriter

Installation

composer require temant-framework/temant-fault

Quick Start

use TemantFramework\Fault\ExceptionHandler;

$handler = new ExceptionHandler();
$handler
    ->setDebug(true)
    ->setApplicationName('My App')
    ->setEditor('vscode')
    ->register();

// That's it. Any uncaught exception will now render a rich error page.

Usage

Basic Setup

use TemantFramework\Fault\ExceptionHandler;

$handler = new ExceptionHandler();
$handler->setDebug(true)->register();

Production Mode

In production, disable debug mode to show a safe, generic error page:

$handler->setDebug(false)->register();

Editor Integration

Configure clickable "Open in editor" links for your IDE:

// Supported: phpstorm, vscode, sublime, atom, idea, netbeans
$handler->setEditor('phpstorm');

Listener Callbacks

Add listeners to log or report exceptions before rendering:

$handler->addListener(function (\Throwable $e): void {
    error_log($e->getMessage());
});

$handler->addListener(function (\Throwable $e): void {
    Sentry::captureException($e);
});

Custom Renderers

Replace any built-in renderer with your own:

use TemantFramework\Fault\ContentType;
use TemantFramework\Fault\Renderer\RendererInterface;
use TemantFramework\Fault\ErrorContext;

$handler->setRenderer(ContentType::Json, new class implements RendererInterface {
    public function render(ErrorContext $context, bool $debug = true): string
    {
        return json_encode(['error' => $context->message]);
    }

    public function contentType(): string
    {
        return 'application/json';
    }
});

Programmatic Rendering

Render exceptions without outputting them:

use TemantFramework\Fault\ContentType;

$html = $handler->render($exception, ContentType::Html);
$json = $handler->render($exception, ContentType::Json);
$xml  = $handler->render($exception, ContentType::Xml);
$text = $handler->render($exception, ContentType::Text);

Default Content Type

Change the fallback format when content negotiation has no match:

use TemantFramework\Fault\ContentType;

$handler->setDefaultContentType(ContentType::Json);

Renderers

Renderer Content Type Debug Output Production Output
HtmlRenderer text/html Interactive debug page Minimal 500 page
JsonRenderer application/json Full error JSON {"error": {"message": "Internal Server Error"}}
XmlRenderer application/xml Full error XML <error><message>Internal Server Error</message></error>
PlainTextRenderer text/plain Stack trace text Internal Server Error

Keyboard Shortcuts (HTML Renderer)

Key Action
j / k or Arrow keys Navigate stack frames
/ Focus frame search
t Toggle light/dark theme
c Copy error to clipboard

Development

# Install dependencies
composer install

# Run tests
composer phpunit

# Run static analysis
composer phpstan

# Run all checks
composer test

# Generate coverage report
composer coverage

Project Structure

fault/
├── src/
│   ├── ContentType.php          # Content type enum with negotiation
│   ├── ErrorContext.php          # Immutable exception data container
│   ├── ExceptionHandler.php     # Central handler (main entry point)
│   └── Renderer/
│       ├── RendererInterface.php # Renderer contract
│       ├── HtmlRenderer.php     # Rich interactive HTML pages
│       ├── JsonRenderer.php     # Structured JSON output
│       ├── XmlRenderer.php      # Well-formed XML documents
│       └── PlainTextRenderer.php# Plain text for CLI/logs
├── tests/
│   └── Unit/                    # PHPUnit test suite
├── examples/
│   └── basic.php                # Usage example
├── build/                       # Cache, coverage (gitignored)
├── composer.json
├── phpunit.xml
├── phpstan.neon                 # PHPStan level 9
└── LICENSE                      # MIT

License

Fault is open-source software licensed under the MIT License.

Part of the Temant Framework.

temant-framework/temant-fault 适用场景与选型建议

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

它主要适用于以下技术方向: 「framework」 「debug」 「exception」 「error」 「handler」 「fault」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 temant-framework/temant-fault 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-21