2017 © Pedro Peláez
 

library httpstatuscode

PHP library to get the meaning from HTTP response status codes.

image

josantonius/httpstatuscode

PHP library to get the meaning from HTTP response status codes.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 24 % Grown

The README.md

PHP HTTP Status Code library

Latest Stable Version License Total Downloads CI CodeCov PSR1 PSR4 PSR12, (*1)

Translations: Español, (*2)

PHP library to get HTTP status code messages and definitions., (*3)



Requirements

  • Operating System: Linux | Windows., (*4)

  • PHP versions: 8.0 | 8.1 | 8.2., (*5)

Installation

The preferred way to install this extension is through Composer., (*6)

To install PHP HTTP Status Code library, simply:, (*7)

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:, (*8)

composer require josantonius/http-status-code --prefer-source

You can also clone the complete repository with Git:, (*9)

git clone https://github.com/josantonius/http-status-code.git

Available Classes

HttpStatusCode Class

Josantonius\HttpStatusCode\HttpStatusCode, (*10)

Create a new instance defining the language:, (*11)

/**
 * @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:, (*12)

public function getMessage(int $code): string|null;

Gets the messages of all HTTP status codes:, (*13)

public function getMessages(): array;

Gets definition of an HTTP status code:, (*14)

public function getDefinition(int $code): string|null;

Gets the definitions of all HTTP status codes:, (*15)

public function getDefinitions(): array;

Gets messages and definitions of all HTTP status codes:, (*16)

public function getAll(): array;

Exceptions Used

use Josantonius\HttpStatusCode\UnsupportedLanguageException;

Usage

Example of use for this library:, (*17)

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:, (*18)

'Not Found'

Gets the messages of all HTTP status codes

use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode();

$httpStatusCode->getMessages();

Returns:, (*19)

[
    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:, (*20)

'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:, (*21)

[
    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, (*22)

Tests

To run tests you just need composer and to execute the following:, (*23)

git clone https://github.com/josantonius/php-http-status-code.git
cd php-http-status-code
composer install

Run unit tests with PHPUnit:, (*24)

composer phpunit

Run code standard tests with PHPCS:, (*25)

composer phpcs

Run PHP Mess Detector tests to detect inconsistencies in code style:, (*26)

composer phpmd

Run all previous tests:, (*27)

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., (*28)

Contribution

Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue., (*29)

Thanks to all contributors! :heart:, (*30)

If this project helps you to reduce your development time, you can sponsor me to support my open source work :blush:, (*31)

License

This repository is licensed under the MIT License., (*32)

Copyright © 2016-present, Josantonius, (*33)

The Versions

06/01 2018

dev-master

9999999-dev

PHP library to get the meaning from HTTP response status codes.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

php http hhvm http status code

06/01 2018

1.1.6

1.1.6.0

PHP library to get the meaning from HTTP response status codes.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

php http hhvm http status code

12/11 2017

1.1.5

1.1.5.0

PHP library to get the meaning from HTTP response status codes.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

php http hhvm http status code

31/10 2017

1.1.4

1.1.4.0

PHP library to get the meaning from HTTP response status codes.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

php http hhvm http status code

17/09 2017

1.1.3

1.1.3.0

PHP library to get the meaning from HTTP response status codes.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

php http hhvm http status code

18/07 2017

1.1.2

1.1.2.0

PHP library to get the meaning from HTTP response status codes.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

php http hhvm http status code

18/03 2017

1.1.1

1.1.1.0

PHP library to get the meaning from HTTP response status codes.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

php http hhvm http status code

19/12 2016

1.0.0

1.0.0.0

PHP library to get the meaning from HTTP response status codes.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

php http hhvm http status code