PHP library to get HTTP status code definitions
MIT License
Translations: Español
PHP library to get HTTP status code messages and definitions.
Operating System: Linux | Windows.
PHP versions: 8.0 | 8.1 | 8.2.
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
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;
use Josantonius\HttpStatusCode\UnsupportedLanguageException;
Example of use for this library:
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.
use Josantonius\HttpStatusCode\HttpStatusCode;
$httpStatusCode = new HttpStatusCode();
$httpStatusCode->getMessage(404);
Returns:
'Not Found'
use Josantonius\HttpStatusCode\HttpStatusCode;
$httpStatusCode = new HttpStatusCode();
$httpStatusCode->getMessages();
Returns:
[
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
(...)
]
use Josantonius\HttpStatusCode\HttpStatusCode;
$httpStatusCode = new HttpStatusCode();
$httpStatusCode->getDefinition(404);
Returns:
'The requested resource could not be found but (...)'
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 (...)',
(...)
]
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 (...)',
],
(...)
]
https://gist.github.com/Josantonius/0a889ab6f18db2fcefda15a039613293
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
Detailed changes for each release are documented in the release notes.
Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue.
Thanks to all contributors! ❤️
If this project helps you to reduce your development time, you can sponsor me to support my open source work 😊
This repository is licensed under the MIT License.
Copyright © 2016-present, Josantonius