timezhero/laravel-rfc9457
Composer 安装命令:
composer require timezhero/laravel-rfc9457
包简介
RFC 9457 Problem Details for Laravel exceptions
README 文档
README
A Laravel package that standardizes API error responses using the RFC 9457 Problem Details specification. Exceptions opt in via a trait and PHP attributes — no base class required, no HTTP coupling on your domain exceptions.
Installation
composer require timezhero/laravel-rfc9457
The service provider is auto-discovered.
Quick start
1. Register the handler in bootstrap/app.php:
use TimeZHero\Rfc9457\ProblemDetailsHandler; return Application::configure(basePath: dirname(__DIR__)) ->withExceptions(function (Exceptions $exceptions): void { ProblemDetailsHandler::register($exceptions); }) ->create();
2. Scaffold an exception:
php artisan make:problem-exception InsufficientStock
3. Throw it:
throw new InsufficientStockException(productId: 42, requested: 30, available: 5);
Response (409, application/problem+json):
{
"type": "/problems/insufficient-stock",
"title": "Insufficient Stock",
"detail": "The requested quantity of 30 exceeds the available stock of 5.",
"status": 409,
"instance": "/api/orders",
"product_id": 42,
"requested": 30,
"available": 5
}
Validation errors, HTTP exceptions, and generic 5xx are also wrapped automatically.
CLI
| Command | What it does |
|---|---|
php artisan make:problem-exception {name} |
Creates exception class + translation entry + documentation view |
php artisan vendor:publish --tag=rfc9457-config |
Publish config |
php artisan vendor:publish --tag=rfc9457-views |
Publish views to customize the docs layout |
Advanced
Manual exception
#[Problem('Rate Limit Exceeded', Response::HTTP_TOO_MANY_REQUESTS)] class RateLimitExceededException extends \RuntimeException { use ProblemRfc9457; public function __construct( #[Extension(description: 'Seconds to wait before retrying.')] private readonly int $retryAfterSeconds, ) { parent::__construct('Internal log message'); } protected function detail(): string { return __('exceptions.rate_limit_exceeded.detail', [ 'retry_after_seconds' => $this->retryAfterSeconds, ]); } }
#[Problem]— title + HTTP status. Type URI is derived from class name. Omit to auto-derive everything (defaults to 500)#[Extension]— marks properties as extension fields (snake_cased in output). Usename:to override the keydetail()— user-facing message (separate from internal$message). Return''to omitextensions()— override to add computed fields at runtime. Merged with attribute extensions
Translations
Convention-based in lang/{locale}/exceptions.php:
'insufficient_stock' => [ 'title' => 'Insufficient Stock', 'detail' => 'Requested :requested but only :available available.', ],
Falls back to the raw #[Problem] title if no translation exists.
Documentation pages
Each exception gets a page at /problems/{slug}. Add a description view at resources/views/vendor/rfc9457/details/{slug}.blade.php. Extensions and metadata are rendered automatically.
Configuration
// config/rfc9457.php return [ 'exception_namespace' => 'App\\Exceptions', 'documentation' => [ 'enabled' => true, // set false to disable route + views entirely 'route_prefix' => '/problems', ], ];
timezhero/laravel-rfc9457 适用场景与选型建议
timezhero/laravel-rfc9457 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「exceptions」 「api」 「laravel」 「problem-details」 「rfc9457」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 timezhero/laravel-rfc9457 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 timezhero/laravel-rfc9457 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 timezhero/laravel-rfc9457 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
php7ify is a project that brings new php7 classes and exceptions to php 5.x.
The CodenamePHP Platform core that contains basic interfaces, exceptions etc..
A simple package to better handle Exceptions.
A PSR-7 compatible library for making CRUD API endpoints
Monitors errors and exceptions and reports them to Rollbar
Creates & updates issues on a GitLab repository from Symfony2 exceptions
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2026-04-30