josantonius / http-status-code
PHP 库,用于获取 HTTP 状态码消息和定义。
v2.0.4
2022-09-29 16:50 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
README
翻译: 西班牙语
PHP 库,用于获取 HTTP 状态码消息和定义。
需求
-
操作系统:Linux | Windows。
-
PHP 版本:8.0 | 8.1 | 8.2。
安装
安装此扩展的首选方法是通过Composer。
要安装 PHP HTTP 状态码库,只需
composer require josantonius/http-status-code
上述命令将仅安装必要的文件,如果您想 下载整个源代码,可以使用
composer require josantonius/http-status-code --prefer-source
您也可以使用 Git 克隆完整仓库
git clone https://github.com/josantonius/http-status-code.git
可用类
HttpStatusCode 类
Josantonius\HttpStatusCode\HttpStatusCode
创建一个新的实例,定义语言
/** * @param string $language The language in which the data will be retrieved. * * Available languages: en (English) * es (Spanish) * * @throws UnsupportedLanguageException if language is not supported. */ public function __construct(string $language = 'en');
获取 HTTP 状态码的消息
public function getMessage(int $code): string|null;
获取所有 HTTP 状态码的消息
public function getMessages(): array;
获取 HTTP 状态码的定义
public function getDefinition(int $code): string|null;
获取所有 HTTP 状态码的定义
public function getDefinitions(): array;
获取所有 HTTP 状态码的消息和定义
public function getAll(): array;
使用的异常
use Josantonius\HttpStatusCode\UnsupportedLanguageException;
用法
此库的使用示例
创建一个新的实例,定义语言
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); // Gets the messages in English.
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode('es'); // Gets the messages in Spanish.
获取 HTTP 状态码的消息
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getMessage(404);
返回
'Not Found'
获取所有 HTTP 状态码的消息
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getMessages();
返回
[ 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', (...) ]
获取 HTTP 状态码的定义
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getDefinition(404);
返回
'The requested resource could not be found but (...)'
获取所有 HTTP 状态码的定义
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getDefinitions();
返回
[ 100 => 'The server has received the request (...)', 101 => 'The requester has asked the server (...)', 102 => 'A WebDAV request may contain many (...)', (...) ]
获取所有 HTTP 状态码的消息和定义
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getAll();
[ 100 => [ 'message' => 'Continue', 'definition' => 'The server has received the request (...)', ], 101 => [ 'message' => 'Switching Protocols', 'definition' => 'The requester has asked the server (...)', ], 102 => [ 'message' => 'Processing', 'definition' => 'A WebDAV request may contain many (...)', ], (...) ]
JSON 格式列表
https://gist.github.com/Josantonius/0a889ab6f18db2fcefda15a039613293
测试
git clone https://github.com/josantonius/php-http-status-code.git
cd php-http-status-code
composer install
使用 PHPUnit 运行单元测试
composer phpunit
使用 PHPCS 运行代码标准测试
composer phpcs
运行 PHP Mess Detector 测试以检测代码风格的冲突
composer phpmd
运行所有之前的测试
composer tests
待办事项
- 添加新功能
- 改进测试
- 改进文档
- 改进 README 文件中的英文翻译
- 重构代码以禁用代码风格规则(请参阅 phpmd.xml 和 phpcs.xml)
变更日志
每个版本的详细更改记录在发行说明中。
贡献
在发起拉取请求、开始讨论或报告问题之前,请务必阅读贡献指南。
感谢所有贡献者! ❤️
赞助商
如果您觉得这个项目帮助您减少了开发时间,您可以赞助我以支持我的开源工作 😊
许可证
此仓库受MIT 许可证的许可。
版权 © 2016-至今,Josantonius