timefrontiers/php-instance-error
Composer 安装命令:
composer require timefrontiers/php-instance-error
包简介
PHP Instance Error handler with access-based filtering
README 文档
README
Extract and filter errors from objects based on user access rank.
Installation
composer require timefrontiers/php-instance-error
Overview
InstanceError extracts errors from any object that has:
- A
getErrors()method (recommended, used byHasErrorstrait), or - A public
$errorsproperty (legacy)
Errors are filtered based on the user's access rank, so sensitive system errors only appear to developers/admins.
Error Format
Errors must follow this format:
[min_rank, code, message, file, line] // Example: [0, 256, 'Invalid email format', '/app/User.php', 42]
Where min_rank is the minimum AccessRank value required to see this error.
Usage
Basic Usage
use TimeFrontiers\InstanceError; // Extract errors visible to current user (uses global $session) $extractor = new InstanceError($userObject); $errors = $extractor->get(); // Get errors for a specific context $loginErrors = $extractor->get('login'); // Get only error messages (strings) $messages = $extractor->get('login', true);
Override Rank
use TimeFrontiers\InstanceError; use TimeFrontiers\AccessRank; // Show ALL errors regardless of rank $extractor = new InstanceError($object, true); // Show errors visible to DEVELOPER rank $extractor = new InstanceError($object, AccessRank::DEVELOPER); // Show errors visible to rank 5 $extractor = new InstanceError($object, 5);
Helper Methods
$extractor = new InstanceError($object); // Check if errors exist if ($extractor->has('validation')) { // ... } // Count visible errors $count = $extractor->count(); $validationCount = $extractor->count('validation'); // Get first error message $first = $extractor->first(); // Get all messages as flat array $allMessages = $extractor->messages();
Logging Errors
If timefrontiers/php-error-log is installed:
$extractor = new InstanceError($object, true); // Log all errors $extractor->log(); // Log specific context $extractor->log('database'); // Log to specific file $extractor->log('database', '/var/log/app/db-errors.log');
Adding Errors
$extractor = new InstanceError($object); // Add an error to the collection $extractor->put('custom', [ AccessRank::GUEST->value, // min_rank 400, // code 'Something went wrong', // message __FILE__, // file __LINE__ // line ]);
Rank Resolution
When no override is provided, rank is resolved in this order:
- Global
$session->access_rankproperty - Global
$session->access_rank()method - Default:
AccessRank::GUEST(0)
Integration with HasErrors Trait
Objects using the HasErrors trait work seamlessly:
use TimeFrontiers\Helper\HasErrors; class MyService { use HasErrors; public function process():bool { if ($error) { $this->_userError('process', 400, 'Processing failed'); return false; } return true; } } // Extract errors $service = new MyService(); $service->process(); $extractor = new InstanceError($service); $errors = $extractor->get('process');
Access Rank Levels
| Rank | Value | Typical Use |
|---|---|---|
| GUEST | 0 | Validation, user-facing errors |
| USER | 1 | Basic user errors |
| MODERATOR | 4 | Business logic errors |
| DEVELOPER | 7 | SQL, connection errors |
| SUPERADMIN | 8 | Sensitive debug info |
Dependencies
timefrontiers/php-core- ForAccessRankenumtimefrontiers/php-has-errors- For error handling trait
License
MIT
timefrontiers/php-instance-error 适用场景与选型建议
timefrontiers/php-instance-error 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「error」 「filtering」 「access-control」 「instance」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 timefrontiers/php-instance-error 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 timefrontiers/php-instance-error 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 timefrontiers/php-instance-error 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Modern PHP Sanitization Library
PHP Error Handler module that captures and displays all throwable errors in a given format, making debugging easier and more efficient
Laravel package for rapid CRUD API scaffolding with filtering, sorting, pagination and CSV export
A Laravel package that contains queries for constructing a datatable
Error and Exception override and observers.
Error handler based on Booboo with HTML and JSON support
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 4
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-14