Translations: Español
PHP library to get HTTP status code messages and definitions.
Version 1.x is considered as deprecated and unsupported. In this version (2.x) the library was completely restructured. It is recommended to review the documentation for this version and make the necessary changes before starting to use it, as it not be compatible with version 1.x.
- Requirements
- Installation
- Available Methods
- Quick Start
- Usage
- List in JSON format
- Tests
- TODO
- Changelog
- Contribution
- Sponsor
- License
Esta biblioteca es compatible con las versiones de PHP: 8.0 | 8.1.
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 methods in this library:
$httpStatusCode = new HttpStatusCode(string $language = 'en');
@param $language
The language in which the data will be retrieved. Available languages:
'en' (English) and
'es' (Spanish).
@throws UnsupportedLanguageException
if language is not supported.
$httpStatusCode->getMessage(int $code): string|null
$httpStatusCode->getMessages(): array
$httpStatusCode->getDefinition(int $code): string|null
$httpStatusCode->getDefinitions(): array
$httpStatusCode->getAll(): array
To use this library with Composer:
require __DIR__ . '/vendor/autoload.php';
use Josantonius\HttpStatusCode\HttpStatusCode;
Example of use for this library:
$httpStatusCode = new HttpStatusCode(); // Gets the messages in English.
$httpStatusCode = new HttpStatusCode('es'); // Gets the messages in Spanish.
$httpStatusCode->getMessage(404);
Returns:
'Not Found'
$httpStatusCode->getMessages();
Returns:
[
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
(...)
]
$httpStatusCode->getDefinition(404);
Returns:
'The requested resource could not be found but (...)'
$httpStatusCode->getDefinitions();
Returns:
[
100 => 'The server has received the request (...)',
101 => 'The requester has asked the server (...)',
102 => 'A WebDAV request may contain many (...)',
(...)
]
$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 PSR12 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
- 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)
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