josantonius/httpstatuscode
最新稳定版本:v2.0.4
Composer 安装命令:
composer require josantonius/httpstatuscode
包简介
PHP library to get HTTP status code messages and definitions.
关键字:
README 文档
README
Translations: Español
PHP library to get HTTP status code messages and definitions.
- Requirements
- Installation
- Available Classes
- Exceptions Used
- Usage
- List in JSON format
- Tests
- TODO
- Changelog
- Contribution
- Sponsor
- License
Requirements
-
Operating System: Linux | Windows.
-
PHP versions: 8.0 | 8.1 | 8.2.
Installation
The preferred way to install this extension is through Composer.
To install PHP HTTP Status Code library, simply:
composer require josantonius/http-status-code
The previous command will only install the necessary files, if you prefer to download the entire source code you can use:
composer require josantonius/http-status-code --prefer-source
You can also clone the complete repository with Git:
git clone https://github.com/josantonius/http-status-code.git
Available Classes
HttpStatusCode Class
Josantonius\HttpStatusCode\HttpStatusCode
Create a new instance defining the language:
/** * @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');
Gets message of an HTTP status code:
public function getMessage(int $code): string|null;
Gets the messages of all HTTP status codes:
public function getMessages(): array;
Gets definition of an HTTP status code:
public function getDefinition(int $code): string|null;
Gets the definitions of all HTTP status codes:
public function getDefinitions(): array;
Gets messages and definitions of all HTTP status codes:
public function getAll(): array;
Exceptions Used
use Josantonius\HttpStatusCode\UnsupportedLanguageException;
Usage
Example of use for this library:
Create a new instance defining the language
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.
Gets message of an HTTP status code
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getMessage(404);
Returns:
'Not Found'
Gets the messages of all HTTP status codes
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getMessages();
Returns:
[
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
(...)
]
Gets definition of an HTTP status code
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getDefinition(404);
Returns:
'The requested resource could not be found but (...)'
Gets the definitions of all HTTP status codes
use Josantonius\HttpStatusCode\HttpStatusCode; $httpStatusCode = new HttpStatusCode(); $httpStatusCode->getDefinitions();
Returns:
[
100 => 'The server has received the request (...)',
101 => 'The requester has asked the server (...)',
102 => 'A WebDAV request may contain many (...)',
(...)
]
Gets messages and definitions of all HTTP status codes
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 (...)',
],
(...)
]
List in JSON format
https://gist.github.com/Josantonius/0a889ab6f18db2fcefda15a039613293
Tests
To run tests you just need composer and to execute the following:
git clone https://github.com/josantonius/php-http-status-code.git
cd php-http-status-code
composer install
Run unit tests with PHPUnit:
composer phpunit
Run code standard tests with PHPCS:
composer phpcs
Run PHP Mess Detector tests to detect inconsistencies in code style:
composer phpmd
Run all previous tests:
composer tests
TODO
- Add new feature
- Improve tests
- Improve documentation
- Improve English translation in the README file
- Refactor code for disabled code style rules (see phpmd.xml and phpcs.xml)
Changelog
Detailed changes for each release are documented in the release notes.
Contribution
Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue.
Thanks to all contributors! ❤️
Sponsor
If this project helps you to reduce your development time, you can sponsor me to support my open source work 😊
License
This repository is licensed under the MIT License.
Copyright © 2016-present, Josantonius
josantonius/httpstatuscode 适用场景与选型建议
josantonius/httpstatuscode 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2022 年 07 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「http」 「http-status-code」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 josantonius/httpstatuscode 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 josantonius/httpstatuscode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 josantonius/httpstatuscode 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easily connect the necessary language packs to the application
repository php library
An exception that contains http status code
PHP List of HTTP status codes, messages and description for them.
PHP library to get HTTP status code messages and definitions.
http客户端
统计信息
- 总下载量: 8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-30