Files
http-status/src/CodesEnum.php
Ron Rise eb89c9d96f
All checks were successful
Publish Release Package / publish (push) Successful in 29s
Add HTTP status codes enumeration and configuration files
2025-06-20 08:32:46 -04:00

212 lines
9.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Siteworxpro\HttpStatus;
/**
* Class CodesEnum
*
* This class defines HTTP status codes as constants.
* It provides a way to reference HTTP status codes in a type-safe manner.
*
* @package Siteworxpro\HttpStatus
*/
enum CodesEnum: int
{
public const int CONTINUE = 100;
public const int SWITCHING_PROTOCOLS = 101;
public const int PROCESSING = 102;
public const int EARLY_HINTS = 103;
public const int OK = 200;
public const int CREATED = 201;
public const int ACCEPTED = 202;
public const int NON_AUTHORITATIVE_INFORMATION = 203;
public const int NO_CONTENT = 204;
public const int RESET_CONTENT = 205;
public const int PARTIAL_CONTENT = 206;
public const int MULTI_STATUS = 207;
public const int ALREADY_REPORTED = 208;
public const int IM_USED = 226;
public const int MULTIPLE_CHOICES = 300;
public const int MOVED_PERMANENTLY = 301;
public const int FOUND = 302;
public const int SEE_OTHER = 303;
public const int NOT_MODIFIED = 304;
public const int USE_PROXY = 305;
public const int TEMPORARY_REDIRECT = 307;
public const int PERMANENT_REDIRECT = 308;
public const int BAD_REQUEST = 400;
public const int UNAUTHORIZED = 401;
public const int PAYMENT_REQUIRED = 402;
public const int FORBIDDEN = 403;
public const int NOT_FOUND = 404;
public const int METHOD_NOT_ALLOWED = 405;
public const int NOT_ACCEPTABLE = 406;
public const int PROXY_AUTHENTICATION_REQUIRED = 407;
public const int REQUEST_TIMEOUT = 408;
public const int CONFLICT = 409;
public const int GONE = 410;
public const int LENGTH_REQUIRED = 411;
public const int PRECONDITION_FAILED = 412;
public const int PAYLOAD_TOO_LARGE = 413;
public const int URI_TOO_LONG = 414;
public const int UNSUPPORTED_MEDIA_TYPE = 415;
public const int RANGE_NOT_SATISFIABLE = 416;
public const int EXPECTATION_FAILED = 417;
public const int IM_A_TEAPOT = 418;
public const int MISDIRECTED_REQUEST = 421;
public const int UNPROCESSABLE_ENTITY = 422;
public const int LOCKED = 423;
public const int FAILED_DEPENDENCY = 424;
public const int TOO_EARLY = 425;
public const int UPGRADE_REQUIRED = 426;
public const int PRECONDITION_REQUIRED = 428;
public const int TOO_MANY_REQUESTS = 429;
public const int REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
public const int UNAVAILABLE_FOR_LEGAL_REASONS = 451;
public const int INTERNAL_SERVER_ERROR = 500;
public const int NOT_IMPLEMENTED = 501;
public const int BAD_GATEWAY = 502;
public const int SERVICE_UNAVAILABLE = 503;
public const int GATEWAY_TIMEOUT = 504;
public const int HTTP_VERSION_NOT_SUPPORTED = 505;
public const int VARIANT_ALSO_NEGOTIATES = 506;
public const int INSUFFICIENT_STORAGE = 507;
public const int LOOP_DETECTED = 508;
public const int NOT_EXTENDED = 510;
public const int NETWORK_AUTHENTICATION_REQUIRED = 511;
public const int NETWORK_CONNECT_TIMEOUT_ERROR = 599;
/**
* Returns the string representation of the HTTP status code.
*
* @return string The string representation of the HTTP status code.
*/
public function toString(): string
{
return match ($this->value) {
self::CONTINUE => 'Continue',
self::SWITCHING_PROTOCOLS => 'Switching Protocols',
self::PROCESSING => 'Processing',
self::EARLY_HINTS => 'Early Hints',
self::OK => 'OK',
self::CREATED => 'Created',
self::ACCEPTED => 'Accepted',
self::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',
self::NO_CONTENT => 'No Content',
self::RESET_CONTENT => 'Reset Content',
self::PARTIAL_CONTENT => 'Partial Content',
self::MULTI_STATUS => 'Multi-Status',
self::ALREADY_REPORTED => 'Already Reported',
self::IM_USED => 'IM Used',
self::MULTIPLE_CHOICES => 'Multiple Choices',
self::MOVED_PERMANENTLY => 'Moved Permanently',
self::FOUND => 'Found',
self::SEE_OTHER => 'See Other',
self::NOT_MODIFIED => 'Not Modified',
self::USE_PROXY => 'Use Proxy',
self::TEMPORARY_REDIRECT => 'Temporary Redirect',
self::PERMANENT_REDIRECT => 'Permanent Redirect',
self::BAD_REQUEST => 'Bad Request',
self::UNAUTHORIZED => 'Unauthorized',
self::PAYMENT_REQUIRED => 'Payment Required',
self::FORBIDDEN => 'Forbidden',
self::NOT_FOUND => 'Not Found',
self::METHOD_NOT_ALLOWED => 'Method Not Allowed',
self::NOT_ACCEPTABLE => 'Not Acceptable',
self::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',
self::REQUEST_TIMEOUT => 'Request Timeout',
self::CONFLICT => 'Conflict',
self::GONE => 'Gone',
self::LENGTH_REQUIRED => 'Length Required',
self::PRECONDITION_FAILED => 'Precondition Failed',
self::PAYLOAD_TOO_LARGE => 'Payload Too Large',
self::URI_TOO_LONG => 'URI Too Long',
self::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',
self::RANGE_NOT_SATISFIABLE => 'Range Not Satisfiable',
self::EXPECTATION_FAILED => 'Expectation Failed',
self::IM_A_TEAPOT => "I'm a teapot",
self::MISDIRECTED_REQUEST => "Misdirected Request",
self::UNPROCESSABLE_ENTITY => "Unprocessable Entity",
self::LOCKED => 'Locked',
self::FAILED_DEPENDENCY => 'Failed Dependency',
self::TOO_EARLY => 'Too Early',
self::UPGRADE_REQUIRED => 'Upgrade Required',
self::PRECONDITION_REQUIRED => 'Precondition Required',
self::TOO_MANY_REQUESTS => 'Too Many Requests',
self::REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large',
self::UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons',
self::INTERNAL_SERVER_ERROR => 'Internal Server Error',
self::NOT_IMPLEMENTED => 'Not Implemented',
self::BAD_GATEWAY => 'Bad Gateway',
self::SERVICE_UNAVAILABLE => 'Service Unavailable',
self::GATEWAY_TIMEOUT => 'Gateway Timeout',
self::HTTP_VERSION_NOT_SUPPORTED => 'HTTP Version Not Supported',
self::VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates',
self::INSUFFICIENT_STORAGE => 'Insufficient Storage',
self::LOOP_DETECTED => 'Loop Detected',
self::NOT_EXTENDED => 'Not Extended',
self::NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required',
self::NETWORK_CONNECT_TIMEOUT_ERROR => 'Network Connect Timeout Error',
};
}
public static function fromCode(int $code): CodesEnum
{
return match ($code) {
self::CONTINUE => self::CONTINUE,
self::SWITCHING_PROTOCOLS => self::SWITCHING_PROTOCOLS,
self::PROCESSING => self::PROCESSING,
self::EARLY_HINTS => self::EARLY_HINTS,
self::OK => self::OK,
self::CREATED => self::CREATED,
self::ACCEPTED => self::ACCEPTED,
self::NON_AUTHORITATIVE_INFORMATION => self::NON_AUTHORITATIVE_INFORMATION,
self::NO_CONTENT => self::NO_CONTENT,
self::RESET_CONTENT => self::RESET_CONTENT,
self::PARTIAL_CONTENT => self::PARTIAL_CONTENT,
self::MULTI_STATUS => self::MULTI_STATUS,
self::ALREADY_REPORTED => self::ALREADY_REPORTED,
self::IM_USED => self::IM_USED,
self::MULTIPLE_CHOICES => self::MULTIPLE_CHOICES,
self::MOVED_PERMANENTLY => self::MOVED_PERMANENTLY,
self::FOUND => self::FOUND,
self::SEE_OTHER => self::SEE_OTHER,
self::NOT_MODIFIED => self::NOT_MODIFIED,
self::USE_PROXY => self::USE_PROXY,
self::TEMPORARY_REDIRECT => self::TEMPORARY_REDIRECT,
self::PERMANENT_REDIRECT => self::PERMANENT_REDIRECT,
// Client errors
self::BAD_REQUEST => self::BAD_REQUEST,
self::UNAUTHORIZED => self::UNAUTHORIZED,
self::PAYMENT_REQUIRED => self::PAYMENT_REQUIRED,
self::FORBIDDEN => self::FORBIDDEN,
self::NOT_FOUND => self::NOT_FOUND,
self::METHOD_NOT_ALLOWED => self::METHOD_NOT_ALLOWED,
self::NOT_ACCEPTABLE => self::NOT_ACCEPTABLE,
self::PROXY_AUTHENTICATION_REQUIRED => self::PROXY_AUTHENTICATION_REQUIRED,
self::REQUEST_TIMEOUT => self::REQUEST_TIMEOUT,
self::CONFLICT => self::CONFLICT,
self::GONE => self::_GONE_,
// Server errors
self::INTERNAL_SERVER_ERROR => self::INTERNAL_SERVER_ERROR,
self::NOT_IMPLEMENTED => self::NOT_IMPLEMENTED,
self::BAD_GATEWAY => self::BAD_GATEWAY,
self::SERVICE_UNAVAILABLE => self::SERVICE_UNAVAILABLE,
self::GATEWAY_TIMEOUT => self::GATEWAY_TIMEOUT,
self::HTTP_VERSION_NOT_SUPPORTED => self::HTTP_VERSION_NOT_SUPPORTED,
self::VARIANT_ALSO_NEGOTIATES => self::VARIANT_ALSO_NEGOTIATES,
self::INSUFFICIENT_STORAGE => self::INSUFFICIENT_STORAGE,
self::LOOP_DETECTED => self::LOOP_DETECTED,
self::NOT_EXTENDED => self::NOT_EXTENDED,
self::NETWORK_AUTHENTICATION_REQUIRED => self::NETWORK_AUTHENTICATION_REQUIRED,
self::NETWORK_CONNECT_TIMEOUT_ERROR => self::NETWORK_CONNECT_TIMEOUT_ERROR,
default => throw new \InvalidArgumentException("Invalid HTTP status code: $code"),
};
}
}