simplicer/http 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

simplicer/http

最新稳定版本:1.0.0

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.

统计信息

  • 总下载量: 115
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固