mrcl / http-status-codes
HTTP Status Codes library
1.0.1
2021-05-17 14:27 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.5
README
PHP library containing all status codes and their corresponding messages listed in the IANA registry plus 418 I'm a teapot.
Installation
composer require mrcl/http-status-codes
Usage
HttpStatus
use Mrcl\Utils\InternetStandards\HttpStatus;
The HttpStatus
class implements all status codes as constants
HttpStatus::OK // 200 HttpStatus::NOT_FOUND // 404
Additionally, you can retrieve the corresponding status message
HttpStatus::MESSAGES[200] // 'OK' HttpStatus::MESSAGES[HttpStatus::NOT_FOUND] // 'Not Found'
Interfaces
Every status category has its own interface containing the associated codes as constants
1xx Informational
use Mrcl\Utils\InternetStandards\HttpStatusCodes\Informational; Informational::CONTINUE // 100
2xx Success
use Mrcl\Utils\InternetStandards\HttpStatusCodes\Success; Success::ACCEPTED // 202
3xx Redirection
use Mrcl\Utils\InternetStandards\HttpStatusCodes\Redirection; Redirection::MOVED_PERMANENTLY // 301
4xx ClientError
use Mrcl\Utils\InternetStandards\HttpStatusCodes\ClientError; ClientError::BAD_REQUEST // 400
5xx ServerError
use Mrcl\Utils\InternetStandards\HttpStatusCodes\ServerError; ServerError::NETWORK_AUTHENTICATION_REQUIRED // 511