josantonius/httpstatuscode 问题修复 & 功能扩展

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

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

josantonius/httpstatuscode

最新稳定版本:v2.0.4

Composer 安装命令:

composer require josantonius/httpstatuscode

包简介

PHP library to get HTTP status code messages and definitions.

README 文档

README

Latest Stable Version License Total Downloads CI CodeCov PSR1 PSR4 PSR12

Translations: Español

PHP library to get HTTP status code messages and definitions.

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 josantonius/httpstatuscode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 26
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-30