fyre/error
Composer 安装命令:
composer require fyre/error
包简介
An error handling library.
README 文档
README
FyreError is a free, open-source error handling library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/error
In PHP:
use Fyre\Error\ErrorHandler;
Basic Usage
$containeris a Container.$iois a Console.$logManageris a LogManager.$eventManageris an EventManager.$configis a Config.
$errorHandler = new ErrorHandler($container, $io, $logManager, $eventManager, $config);
Default configuration options will be resolved from the "Error" key in the Config.
$optionsis an array containing the configuration options.levelis a number representing the error reporting level, and will default toE_ALL.rendereris a Closure that will be used to render an Exception, and will default to null.logis a boolean indicating whether to log exception messages, and will default to true.
$container->use(Config::class)->set('Error', $options);
Autoloading
It is recommended to bind the ErrorHandler to the Container as a singleton.
$container->singleton(ErrorHandler::class);
Any dependencies will be injected automatically when loading from the Container.
$errorHandler = $container->use(ErrorHandler::class);
Methods
Disable CLI
Disable CLI error handling.
$errorHandler->disableCli();
Enable CLI
Enable CLI error handling.
$errorHandler->enableCli();
Get Exception
Get the current Exception.
$exception = $errorHandler->getException();
Get Renderer
Get the error renderer.
$renderer = $errorHandler->getRenderer();
Register
Register the error handler.
$errorHandler->register();
Render
Render an Exception.
$response = $errorHandler->render($exception);
Set Renderer
Set the error renderer.
$rendereris a Closure that accepts an Exception as the first argument.
$errorHandler->setRenderer($renderer);
The renderer should return a ClientResponse or a string.
Unregister
Unregister the error handler.
$errorHandler->unregister();
Middleware
use Fyre\Error\Middleware\ErrorHandlerMiddleware;
$errorHandleris an ErrorHandler.
$middleware = new ErrorHandlerMiddleware($errorHandler);
Any dependencies will be injected automatically when loading from the Container.
$middleware = $container->use(ErrorHandlerMiddleware::class);
Handle
$requestis a ServerRequest.$nextis a Closure.
$response = $middleware->handle($request, $next);
This method will return a ClientResponse.
Exceptions
Custom exceptions can be created by extending the Fyre\Error\Exceptions\Exception class.
$messageis a string representing the error message.$codeis a number representing the error code, and will default to 500.$previousis an Exception representing the previous exception, and will default to null.
new Exception($message, $code, $previous);
Http Exceptions
Bad Request
400 Bad Request error.
use Fyre\Error\Exceptions\BadRequestException;
Unauthorized
401 Unauthorized error.
use Fyre\Error\Exceptions\UnauthorizedException;
Forbidden
403 Forbidden error.
use Fyre\Error\Exceptions\Forbidden;
Not Found
404 Not Found error.
use Fyre\Error\Exceptions\NotFoundException;
Method Not Allowed
405 Method Not Allowed error.
use Fyre\Error\Exceptions\MethodNotAllowedException;
Not Acceptable
406 Not Acceptable error.
use Fyre\Error\Exceptions\NotAcceptableException;
Conflict
409 Conflict error.
use Fyre\Error\Exceptions\ConflictException;
Gone
410 Gone error.
use Fyre\Error\Exceptions\GoneException;
Internal Server
500 Internal Server error.
use Fyre\Error\Exceptions\InternalServerException;
Not Implemented
501 Not Implemented error.
use Fyre\Error\Exceptions\NotImplementedException;
Service Unavailable
503 Service Unavailable error.
use Fyre\Error\Exceptions\ServiceUnavailableException;
fyre/error 适用场景与选型建议
fyre/error 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 173 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 fyre/error 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fyre/error 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 173
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-03