You've already forked http-status
Refactor CodesEnum to use enum cases for HTTP status codes
All checks were successful
Publish Release Package / publish (push) Successful in 29s
All checks were successful
Publish Release Package / publish (push) Successful in 29s
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php /** @noinspection PhpUnused */
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
@@ -14,73 +14,69 @@ namespace Siteworxpro\HttpStatus;
|
|||||||
*/
|
*/
|
||||||
enum CodesEnum: int
|
enum CodesEnum: int
|
||||||
{
|
{
|
||||||
public const int CONTINUE = 100;
|
case CONTINUE = 100;
|
||||||
public const int SWITCHING_PROTOCOLS = 101;
|
case SWITCHING_PROTOCOLS = 101;
|
||||||
public const int PROCESSING = 102;
|
case PROCESSING = 102;
|
||||||
public const int EARLY_HINTS = 103;
|
case EARLY_HINTS = 103;
|
||||||
|
case OK = 200;
|
||||||
public const int OK = 200;
|
case CREATED = 201;
|
||||||
public const int CREATED = 201;
|
case ACCEPTED = 202;
|
||||||
public const int ACCEPTED = 202;
|
case NON_AUTHORITATIVE_INFORMATION = 203;
|
||||||
public const int NON_AUTHORITATIVE_INFORMATION = 203;
|
case NO_CONTENT = 204;
|
||||||
public const int NO_CONTENT = 204;
|
case RESET_CONTENT = 205;
|
||||||
public const int RESET_CONTENT = 205;
|
case PARTIAL_CONTENT = 206;
|
||||||
public const int PARTIAL_CONTENT = 206;
|
case MULTI_STATUS = 207;
|
||||||
public const int MULTI_STATUS = 207;
|
case ALREADY_REPORTED = 208;
|
||||||
public const int ALREADY_REPORTED = 208;
|
case IM_USED = 226;
|
||||||
public const int IM_USED = 226;
|
case MULTIPLE_CHOICES = 300;
|
||||||
|
case MOVED_PERMANENTLY = 301;
|
||||||
public const int MULTIPLE_CHOICES = 300;
|
case FOUND = 302;
|
||||||
public const int MOVED_PERMANENTLY = 301;
|
case SEE_OTHER = 303;
|
||||||
public const int FOUND = 302;
|
case NOT_MODIFIED = 304;
|
||||||
public const int SEE_OTHER = 303;
|
case USE_PROXY = 305;
|
||||||
public const int NOT_MODIFIED = 304;
|
case TEMPORARY_REDIRECT = 307;
|
||||||
public const int USE_PROXY = 305;
|
case PERMANENT_REDIRECT = 308;
|
||||||
public const int TEMPORARY_REDIRECT = 307;
|
case BAD_REQUEST = 400;
|
||||||
public const int PERMANENT_REDIRECT = 308;
|
case UNAUTHORIZED = 401;
|
||||||
|
case PAYMENT_REQUIRED = 402;
|
||||||
public const int BAD_REQUEST = 400;
|
case FORBIDDEN = 403;
|
||||||
public const int UNAUTHORIZED = 401;
|
case NOT_FOUND = 404;
|
||||||
public const int PAYMENT_REQUIRED = 402;
|
case METHOD_NOT_ALLOWED = 405;
|
||||||
public const int FORBIDDEN = 403;
|
case NOT_ACCEPTABLE = 406;
|
||||||
public const int NOT_FOUND = 404;
|
case PROXY_AUTHENTICATION_REQUIRED = 407;
|
||||||
public const int METHOD_NOT_ALLOWED = 405;
|
case REQUEST_TIMEOUT = 408;
|
||||||
public const int NOT_ACCEPTABLE = 406;
|
case CONFLICT = 409;
|
||||||
public const int PROXY_AUTHENTICATION_REQUIRED = 407;
|
case GONE = 410;
|
||||||
public const int REQUEST_TIMEOUT = 408;
|
case LENGTH_REQUIRED = 411;
|
||||||
public const int CONFLICT = 409;
|
case PRECONDITION_FAILED = 412;
|
||||||
public const int GONE = 410;
|
case PAYLOAD_TOO_LARGE = 413;
|
||||||
public const int LENGTH_REQUIRED = 411;
|
case URI_TOO_LONG = 414;
|
||||||
public const int PRECONDITION_FAILED = 412;
|
case UNSUPPORTED_MEDIA_TYPE = 415;
|
||||||
public const int PAYLOAD_TOO_LARGE = 413;
|
case RANGE_NOT_SATISFIABLE = 416;
|
||||||
public const int URI_TOO_LONG = 414;
|
case EXPECTATION_FAILED = 417;
|
||||||
public const int UNSUPPORTED_MEDIA_TYPE = 415;
|
case IM_A_TEAPOT = 418;
|
||||||
public const int RANGE_NOT_SATISFIABLE = 416;
|
case MISDIRECTED_REQUEST = 421;
|
||||||
public const int EXPECTATION_FAILED = 417;
|
case UNPROCESSABLE_ENTITY = 422;
|
||||||
public const int IM_A_TEAPOT = 418;
|
case LOCKED = 423;
|
||||||
public const int MISDIRECTED_REQUEST = 421;
|
case FAILED_DEPENDENCY = 424;
|
||||||
public const int UNPROCESSABLE_ENTITY = 422;
|
case TOO_EARLY = 425;
|
||||||
public const int LOCKED = 423;
|
case UPGRADE_REQUIRED = 426;
|
||||||
public const int FAILED_DEPENDENCY = 424;
|
case PRECONDITION_REQUIRED = 428;
|
||||||
public const int TOO_EARLY = 425;
|
case TOO_MANY_REQUESTS = 429;
|
||||||
public const int UPGRADE_REQUIRED = 426;
|
case REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
|
||||||
public const int PRECONDITION_REQUIRED = 428;
|
case UNAVAILABLE_FOR_LEGAL_REASONS = 451;
|
||||||
public const int TOO_MANY_REQUESTS = 429;
|
case INTERNAL_SERVER_ERROR = 500;
|
||||||
public const int REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
|
case NOT_IMPLEMENTED = 501;
|
||||||
public const int UNAVAILABLE_FOR_LEGAL_REASONS = 451;
|
case BAD_GATEWAY = 502;
|
||||||
|
case SERVICE_UNAVAILABLE = 503;
|
||||||
public const int INTERNAL_SERVER_ERROR = 500;
|
case GATEWAY_TIMEOUT = 504;
|
||||||
public const int NOT_IMPLEMENTED = 501;
|
case HTTP_VERSION_NOT_SUPPORTED = 505;
|
||||||
public const int BAD_GATEWAY = 502;
|
case VARIANT_ALSO_NEGOTIATES = 506;
|
||||||
public const int SERVICE_UNAVAILABLE = 503;
|
case INSUFFICIENT_STORAGE = 507;
|
||||||
public const int GATEWAY_TIMEOUT = 504;
|
case LOOP_DETECTED = 508;
|
||||||
public const int HTTP_VERSION_NOT_SUPPORTED = 505;
|
case NOT_EXTENDED = 510;
|
||||||
public const int VARIANT_ALSO_NEGOTIATES = 506;
|
case NETWORK_AUTHENTICATION_REQUIRED = 511;
|
||||||
public const int INSUFFICIENT_STORAGE = 507;
|
case NETWORK_CONNECT_TIMEOUT_ERROR = 599;
|
||||||
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.
|
* Returns the string representation of the HTTP status code.
|
||||||
@@ -89,7 +85,7 @@ enum CodesEnum: int
|
|||||||
*/
|
*/
|
||||||
public function toString(): string
|
public function toString(): string
|
||||||
{
|
{
|
||||||
return match ($this->value) {
|
return match ($this) {
|
||||||
self::CONTINUE => 'Continue',
|
self::CONTINUE => 'Continue',
|
||||||
self::SWITCHING_PROTOCOLS => 'Switching Protocols',
|
self::SWITCHING_PROTOCOLS => 'Switching Protocols',
|
||||||
self::PROCESSING => 'Processing',
|
self::PROCESSING => 'Processing',
|
||||||
@@ -159,53 +155,69 @@ enum CodesEnum: int
|
|||||||
public static function fromCode(int $code): CodesEnum
|
public static function fromCode(int $code): CodesEnum
|
||||||
{
|
{
|
||||||
return match ($code) {
|
return match ($code) {
|
||||||
self::CONTINUE => self::CONTINUE,
|
100 => self::CONTINUE,
|
||||||
self::SWITCHING_PROTOCOLS => self::SWITCHING_PROTOCOLS,
|
101 => self::SWITCHING_PROTOCOLS,
|
||||||
self::PROCESSING => self::PROCESSING,
|
102 => self::PROCESSING,
|
||||||
self::EARLY_HINTS => self::EARLY_HINTS,
|
103 => self::EARLY_HINTS,
|
||||||
self::OK => self::OK,
|
200 => self::OK,
|
||||||
self::CREATED => self::CREATED,
|
201 => self::CREATED,
|
||||||
self::ACCEPTED => self::ACCEPTED,
|
202 => self::ACCEPTED,
|
||||||
self::NON_AUTHORITATIVE_INFORMATION => self::NON_AUTHORITATIVE_INFORMATION,
|
203 => self::NON_AUTHORITATIVE_INFORMATION,
|
||||||
self::NO_CONTENT => self::NO_CONTENT,
|
204 => self::NO_CONTENT,
|
||||||
self::RESET_CONTENT => self::RESET_CONTENT,
|
205 => self::RESET_CONTENT,
|
||||||
self::PARTIAL_CONTENT => self::PARTIAL_CONTENT,
|
206 => self::PARTIAL_CONTENT,
|
||||||
self::MULTI_STATUS => self::MULTI_STATUS,
|
207 => self::MULTI_STATUS,
|
||||||
self::ALREADY_REPORTED => self::ALREADY_REPORTED,
|
208 => self::ALREADY_REPORTED,
|
||||||
self::IM_USED => self::IM_USED,
|
226 => self::IM_USED,
|
||||||
self::MULTIPLE_CHOICES => self::MULTIPLE_CHOICES,
|
300 => self::MULTIPLE_CHOICES,
|
||||||
self::MOVED_PERMANENTLY => self::MOVED_PERMANENTLY,
|
301 => self::MOVED_PERMANENTLY,
|
||||||
self::FOUND => self::FOUND,
|
302 => self::FOUND,
|
||||||
self::SEE_OTHER => self::SEE_OTHER,
|
303 => self::SEE_OTHER,
|
||||||
self::NOT_MODIFIED => self::NOT_MODIFIED,
|
304 => self::NOT_MODIFIED,
|
||||||
self::USE_PROXY => self::USE_PROXY,
|
305 => self::USE_PROXY,
|
||||||
self::TEMPORARY_REDIRECT => self::TEMPORARY_REDIRECT,
|
307 => self::TEMPORARY_REDIRECT,
|
||||||
self::PERMANENT_REDIRECT => self::PERMANENT_REDIRECT,
|
308 => self::PERMANENT_REDIRECT,
|
||||||
// Client errors
|
400 => self::BAD_REQUEST,
|
||||||
self::BAD_REQUEST => self::BAD_REQUEST,
|
401 => self::UNAUTHORIZED,
|
||||||
self::UNAUTHORIZED => self::UNAUTHORIZED,
|
402 => self::PAYMENT_REQUIRED,
|
||||||
self::PAYMENT_REQUIRED => self::PAYMENT_REQUIRED,
|
403 => self::FORBIDDEN,
|
||||||
self::FORBIDDEN => self::FORBIDDEN,
|
404 => self::NOT_FOUND,
|
||||||
self::NOT_FOUND => self::NOT_FOUND,
|
405 => self::METHOD_NOT_ALLOWED,
|
||||||
self::METHOD_NOT_ALLOWED => self::METHOD_NOT_ALLOWED,
|
406 => self::NOT_ACCEPTABLE,
|
||||||
self::NOT_ACCEPTABLE => self::NOT_ACCEPTABLE,
|
407 => self::PROXY_AUTHENTICATION_REQUIRED,
|
||||||
self::PROXY_AUTHENTICATION_REQUIRED => self::PROXY_AUTHENTICATION_REQUIRED,
|
408 => self::REQUEST_TIMEOUT,
|
||||||
self::REQUEST_TIMEOUT => self::REQUEST_TIMEOUT,
|
409 => self::CONFLICT,
|
||||||
self::CONFLICT => self::CONFLICT,
|
410 => self::GONE,
|
||||||
self::GONE => self::_GONE_,
|
411 => self::LENGTH_REQUIRED,
|
||||||
// Server errors
|
412 => self::PRECONDITION_FAILED,
|
||||||
self::INTERNAL_SERVER_ERROR => self::INTERNAL_SERVER_ERROR,
|
413 => self::PAYLOAD_TOO_LARGE,
|
||||||
self::NOT_IMPLEMENTED => self::NOT_IMPLEMENTED,
|
414 => self::URI_TOO_LONG,
|
||||||
self::BAD_GATEWAY => self::BAD_GATEWAY,
|
415 => self::UNSUPPORTED_MEDIA_TYPE,
|
||||||
self::SERVICE_UNAVAILABLE => self::SERVICE_UNAVAILABLE,
|
416 => self::RANGE_NOT_SATISFIABLE,
|
||||||
self::GATEWAY_TIMEOUT => self::GATEWAY_TIMEOUT,
|
417 => self::EXPECTATION_FAILED,
|
||||||
self::HTTP_VERSION_NOT_SUPPORTED => self::HTTP_VERSION_NOT_SUPPORTED,
|
418 => self::IM_A_TEAPOT,
|
||||||
self::VARIANT_ALSO_NEGOTIATES => self::VARIANT_ALSO_NEGOTIATES,
|
421 => self::MISDIRECTED_REQUEST,
|
||||||
self::INSUFFICIENT_STORAGE => self::INSUFFICIENT_STORAGE,
|
422 => self::UNPROCESSABLE_ENTITY,
|
||||||
self::LOOP_DETECTED => self::LOOP_DETECTED,
|
423 => self::LOCKED,
|
||||||
self::NOT_EXTENDED => self::NOT_EXTENDED,
|
424 => self::FAILED_DEPENDENCY,
|
||||||
self::NETWORK_AUTHENTICATION_REQUIRED => self::NETWORK_AUTHENTICATION_REQUIRED,
|
425 => self::TOO_EARLY,
|
||||||
self::NETWORK_CONNECT_TIMEOUT_ERROR => self::NETWORK_CONNECT_TIMEOUT_ERROR,
|
426 => self::UPGRADE_REQUIRED,
|
||||||
|
428 => self::PRECONDITION_REQUIRED,
|
||||||
|
429 => self::TOO_MANY_REQUESTS,
|
||||||
|
431 => self::REQUEST_HEADER_FIELDS_TOO_LARGE,
|
||||||
|
451 => self::UNAVAILABLE_FOR_LEGAL_REASONS,
|
||||||
|
500 => self::INTERNAL_SERVER_ERROR,
|
||||||
|
501 => self::NOT_IMPLEMENTED,
|
||||||
|
502 => self::BAD_GATEWAY,
|
||||||
|
503 => self::SERVICE_UNAVAILABLE,
|
||||||
|
504 => self::GATEWAY_TIMEOUT,
|
||||||
|
505 => self::HTTP_VERSION_NOT_SUPPORTED,
|
||||||
|
506 => self::VARIANT_ALSO_NEGOTIATES,
|
||||||
|
507 => self::INSUFFICIENT_STORAGE,
|
||||||
|
508 => self::LOOP_DETECTED,
|
||||||
|
510 => self::NOT_EXTENDED,
|
||||||
|
511 => self::NETWORK_AUTHENTICATION_REQUIRED,
|
||||||
|
599 => self::NETWORK_CONNECT_TIMEOUT_ERROR,
|
||||||
default => throw new \InvalidArgumentException("Invalid HTTP status code: $code"),
|
default => throw new \InvalidArgumentException("Invalid HTTP status code: $code"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user