pavelsterba/http-exceptions
Composer 安装命令:
composer require pavelsterba/http-exceptions
包简介
HTTP status code exceptions for PHP.
关键字:
README 文档
README
If you are creating API, SPL Exceptions are sometimes not the best choice to describe your problem. That is where HTTP Exceptions can be helpful.
Requested data not found? Unauthorized request? XML instead of JSON received? Throw relevant exception!
Installation
Just add it as dependency to your project:
composer require pavelsterba/http-exceptions
Usage
All exceptions can be thrown without any additional information - message and code are predefined.
try { throw new HttpException\ServerError\InternalServerErrorException(); } catch (HttpException\HttpException $e) { echo $e->getMessage(); // 500 Internal Server Error echo $e->getCode(); // 500 }
To get customized instance of exception, you can pass parameters to exception as usual or use static function get(), where you have to specify only message and previous exception:
use HttpException\ServerError\InternalServerErrorException; try { // ... } catch (Exception $ex) { throw InternalServerErrorException::get("Server down, sorry.", $ex); }
Structure
Your API can be fully exception driven since all HTTP statuses from RFC 9110 are implemented as separated exceptions with following hierarchy:
Exception
└─ HttpException\HttpException
├─ HttpException\InformationalException
│ ├─ HttpException\Informational\ContinueException
│ ├─ HttpException\Informational\SwitchingProtocolsException
│ ├─ HttpException\Informational\ProcessingException
│ └─ HttpException\Informational\EarlyHintsException
├─ HttpException\SuccessfulException
│ ├─ HttpException\Successful\OKException
│ ├─ HttpException\Successful\CreatedException
│ ├─ HttpException\Successful\AcceptedException
│ ├─ HttpException\Successful\NonAuthoritativeInformationException
│ ├─ HttpException\Successful\NoContentException
│ ├─ HttpException\Successful\ResetContentException
│ ├─ HttpException\Successful\PartialContentException
│ ├─ HttpException\Successful\MultiStatusException
│ ├─ HttpException\Successful\AlreadyReportedException
│ └─ HttpException\Successful\IMUsedException
├─ HttpException\RedirectionException
│ ├─ HttpException\Redirection\MultipleChoicesException
│ ├─ HttpException\Redirection\MovedPermanentlyException
│ ├─ HttpException\Redirection\FoundException
│ ├─ HttpException\Redirection\SeeOtherException
│ ├─ HttpException\Redirection\NotModifiedException
│ ├─ HttpException\Redirection\UseProxyException
│ ├─ HttpException\Redirection\TemporaryRedirectException
│ └─ HttpException\Redirection\PermanentRedirectException
├─ HttpException\ClientErrorException
│ ├─ HttpException\ClientError\BadRequestException
│ ├─ HttpException\ClientError\UnauthorizedException
│ ├─ HttpException\ClientError\PaymentRequiredException
│ ├─ HttpException\ClientError\ForbiddenException
│ ├─ HttpException\ClientError\NotFoundException
│ ├─ HttpException\ClientError\MethodNotAllowedException
│ ├─ HttpException\ClientError\NotAcceptableException
│ ├─ HttpException\ClientError\ProxyAuthenticationRequiredException
│ ├─ HttpException\ClientError\RequestTimeoutException
│ ├─ HttpException\ClientError\ConflictException
│ ├─ HttpException\ClientError\GoneException
│ ├─ HttpException\ClientError\LengthRequiredException
│ ├─ HttpException\ClientError\PreconditionFailedException
│ ├─ HttpException\ClientError\PayloadTooLargeException
│ ├─ HttpException\ClientError\URITooLongException
│ ├─ HttpException\ClientError\UnsupportedMediaTypeException
│ ├─ HttpException\ClientError\RangeNotSatisfiableException
│ ├─ HttpException\ClientError\ExpectationFailedException
│ ├─ HttpException\ClientError\IMaTeapotException
│ ├─ HttpException\ClientError\MisdirectedRequestException
│ ├─ HttpException\ClientError\UnprocessableEntityException
│ ├─ HttpException\ClientError\LockedException
│ ├─ HttpException\ClientError\FailedDependencyException
│ ├─ HttpException\ClientError\TooEarlyException
│ ├─ HttpException\ClientError\UpgradeRequiredException
│ ├─ HttpException\ClientError\PreconditionRequiredException
│ ├─ HttpException\ClientError\TooManyRequestsException
│ ├─ HttpException\ClientError\RequestHeaderFieldsTooLargeException
│ └─ HttpException\ClientError\UnavailableForLegalReasonsException
└─ HttpException\ServerErrorException
├─ HttpException\ServerError\InternalServerErrorException
├─ HttpException\ServerError\NotImplementedException
├─ HttpException\ServerError\BadGatewayException
├─ HttpException\ServerError\ServiceUnavailableException
├─ HttpException\ServerError\GatewayTimeoutException
├─ HttpException\ServerError\HTTPVersionNotSupportedException
├─ HttpException\ServerError\VariantAlsoNegotiatesException
├─ HttpException\ServerError\InsufficientStorageException
├─ HttpException\ServerError\LoopDetectedException
├─ HttpException\ServerError\NotExtendedException
└─ HttpException\ServerError\NetworkAuthenticationRequiredException
pavelsterba/http-exceptions 适用场景与选型建议
pavelsterba/http-exceptions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 112.4k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2015 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「http」 「exceptions」 「api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pavelsterba/http-exceptions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pavelsterba/http-exceptions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pavelsterba/http-exceptions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
php7ify is a project that brings new php7 classes and exceptions to php 5.x.
repository php library
The CodenamePHP Platform core that contains basic interfaces, exceptions etc..
A simple package to better handle Exceptions.
Monitors errors and exceptions and reports them to Rollbar
Creates & updates issues on a GitLab repository from Symfony2 exceptions
统计信息
- 总下载量: 112.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-28