simplicer/http
Composer 安装命令:
composer require simplicer/http
包简介
Library to manage HTTP status codes and their descriptions.
README 文档
README
This library provides a comprehensive list of HTTP status codes, their texts, and descriptions, as well as utility methods for working with HTTP status codes.
Installation
Use composer to install the library:
composer require simplicer/http
Usage
Accessing Status Codes
You can access status codes directly using the provided constants:
use Simplicer\Http\Status\Code;
echo Code::OK; // Outputs: 200
Accessing Status Texts
Use the getText method to get the text representation of a status code:
echo Code::getText(Code::OK); // Outputs: "OK"
Accessing Status Descriptions
Use the getDescription method to get a description of a status code:
echo Code::getDescription(Code::OK); // Outputs: "The request was successfully processed."
Accessing Status Headers
Use the getStatusHeader method to get a formatted status header:
echo Code::getStatusHeader(Code::OK); // Outputs: "HTTP/1.1 200 OK"
Validating Status Codes
Use the isValidStatusCode method to check if a status code is valid:
var_dump(Code::isValidStatusCode(200)); // Outputs: bool(true)
var_dump(Code::isValidStatusCode(999)); // Outputs: bool(false)
Grouping Status Codes by Category
You can get status codes grouped by their categories:
$statusCodesByCategory = Code::getStatusCodesByCategory();
print_r($statusCodesByCategory);
Calling Status Codes as Methods
You can call status codes as methods directly:
echo Code::OK(); // Outputs: 200
Handling Invalid Status Code Exceptions
This library throws an InvalidStatusCodeException when an invalid HTTP status code is encountered. You can catch and handle this exception in your code as follows:
use Simplicer\Http\Status\Code;
use Simplicer\Http\Status\InvalidStatusCodeException;
try {
$statusCode = Code::INVALID_STATUS_CODE_CONSTANT();
} catch (InvalidStatusCodeException $e) {
echo "Caught exception: " . $e->getMessage() . "\n";
echo "Invalid status code: " . $e->getStatusCode() . "\n";
}
More information
You can check the PHPDoc autogenerated technical documentation in markdown on /doc directory.
Author
Antonio Villamarín
License
This library is licensed under the GPLv3 License.
simplicer/http 适用场景与选型建议
simplicer/http 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 115 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 simplicer/http 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 simplicer/http 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 115
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2024-06-21