0.3.0
2016-12-29 11:39 UTC
Requires
- php: >=5.6.0
Requires (Dev)
- codeclimate/php-test-reporter: ^0.3.2
- phpunit/phpunit: ^5.5
This package is not auto-updated.
Last update: 2024-09-15 01:11:40 UTC
README
一个异常库,可以通过中间件将特定的HTTP错误向上冒泡。
安装
建议您使用Composer来安装peel。
$ composer require avalanche-development/peel
peel需要PHP 5.6或更高版本。
用法
function someMiddleware($request, $response, $next) { $body = (string) $request->getBody(); $body = json_decode($value); if (json_last_error() !== JSON_ERROR_NONE) { throw new AvalancheDevelopment\Peel\HttpError\BadRequest('Invalid JSON'); } // etc }
每个异常实现AvalancheDevelopment\Peel\HttpErrorInterface
接口,强制实现两个方法,getStatusCode
和getStatusMessage
。这些方法为您提供了任何错误处理器的预期HTTP代码和消息。
异常
- BadRequest 400
- Unauthorized 401
- PaymentRequired 402
- Forbidden 403
- NotFound 404
- MethodNotAllowed 405
- NotAcceptable 406
- ProxyAuthenticationRequired 407
- RequestTimeout 408
- Conflict 409
- Gone 410
- LengthRequired 411
- PreconditionFailed 412
- RequestEntityTooLarge 413
- RequestUriTooLong 414
- UnsupportedMediaType 415
- RequestedRangeNotSatisfiable 416
- ExpectationFailed 417
- UnprocessableEntity 422
- Locked 423
- PreconditionRequired 428
- TooManyRequests 429
- RequestHeaderFieldsTooLarge 431
- UnavailableForLegalReasons 451
- InternalServerError 500
- NotImplemented 501
- BadGateway 502
- ServiceUnavailable 503
- GatewayTimeout 504
注意:有关利用这些标准化异常的错误处理器的信息,请参阅avalanche-development/crash-pad。
开发
这个库还在开发中 - 根据需要,可能还会为不同的状态添加额外的选项(例如,错误元数据)。
测试
要执行测试套件,您需要phpunit(以及安装带有开发依赖项的包)。
$ phpunit
许可证
peel遵循MIT许可证。有关更多信息,请参阅许可证文件。