note 129631 added to function.http-response-code
| From: | theking2(at)king.ma | Date: | Wed, 03 Jul 2024 14:24:23 +0000 |
| Subject: | note 129631 added to function.http-response-code | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221405@lists.php.net to get a copy of this message | ||
An int backed enum class to make sure status codes exist and can be
converted to a string when needed.
<?php declare(strict_types=1);
namespace Kingsoft\Http;
enum StatusCode: int
{
case Continue = 100;
case SwitchingProtocols = 101;
case OK = 200;
case Created = 201;
case Accepted = 202;
case NonAuthoritativeInformation = 203;
case NoContent = 204;
case ResetContent = 205;
case PartialContent = 206;
case MultipleChoices = 300;
case MovedPermanently = 301;
case Found = 302;
case SeeOther = 303;
case NotModified = 304;
case UseProxy = 305;
case TemporaryRedirect = 307;
case BadRequest = 400;
case Unauthorized = 401;
case PaymentRequired = 402;
case Forbidden = 403;
case NotFound = 404;
case MethodNotAllowed = 405;
case NotAcceptable = 406;
case ProxyAuthenticationRequired = 407;
case RequestTimeout = 408;
case Conflict = 409;
case Gone = 410;
case LengthRequired = 411;
case PreconditionFailed = 412;
case RequestEntityTooLarge = 413;
case RequestURITooLong = 414;
case UnsupportedMediaType = 415;
case RequestedRangeNotSatisfiable = 416;
case ExpectationFailed = 417;
case InternalServerError = 500;
case NotImplemented = 501;
case BadGateway = 502;
case ServiceUnavailable = 503;
case GatewayTimeout = 504;
case HTTPVersionNotSupported = 505;
/**
* toString
* Current versions of PHP don't accept a magic function here
*
* @param mixed $statusCode
* @return string
*/
public static function toString( StatusCode $statusCode ): string
{
return match ( $statusCode ) {
StatusCode::Continue => 'Continue',
StatusCode::SwitchingProtocols => 'Switching Protocols',
StatusCode::OK => 'OK',
StatusCode::Created => 'Created',
StatusCode::Accepted => 'Accepted',
StatusCode::NonAuthoritativeInformation => 'Non-Authoritative Information',
StatusCode::NoContent => 'No Content',
StatusCode::ResetContent => 'Reset Content',
StatusCode::PartialContent => 'Partial Content',
StatusCode::MultipleChoices => 'Multiple Choices',
StatusCode::MovedPermanently => 'Moved Permanently',
StatusCode::Found => 'Found',
StatusCode::SeeOther => 'See Other',
StatusCode::NotModified => 'Not Modified',
StatusCode::UseProxy => 'Use Proxy',
StatusCode::TemporaryRedirect => 'Temporary Redirect',
StatusCode::BadRequest => 'Bad Request',
StatusCode::Unauthorized => 'Unauthorized',
StatusCode::PaymentRequired => 'Payment Required',
StatusCode::Forbidden => 'Forbidden',
StatusCode::NotFound => 'Not Found',
StatusCode::MethodNotAllowed => 'Method Not Allowed',
StatusCode::NotAcceptable => 'Not Acceptable',
StatusCode::ProxyAuthenticationRequired => 'Proxy Authentication Required',
StatusCode::RequestTimeout => 'Request Timeout',
StatusCode::Conflict => 'Conflict',
StatusCode::Gone => 'Gone',
StatusCode::LengthRequired => 'Length Required',
StatusCode::PreconditionFailed => 'Precondition Failed',
StatusCode::RequestEntityTooLarge => 'Request Entity Too Large',
StatusCode::RequestURITooLong => 'Request-URI Too Long',
StatusCode::UnsupportedMediaType => 'Unsupported Media Type',
StatusCode::RequestedRangeNotSatisfiable => 'Requested Range Not Satisfiable',
StatusCode::ExpectationFailed => 'Expectation Failed',
StatusCode::InternalServerError => 'Internal Server Error',
StatusCode::NotImplemented => 'Not Implemented',
StatusCode::BadGateway => 'Bad Gateway',
StatusCode::ServiceUnavailable => 'Service Unavailable',
StatusCode::GatewayTimeout => 'Gateway Timeout',
StatusCode::HTTPVersionNotSupported => 'HTTP Version Not Supported',
default => 'Unknown HTTP status code'
};
}
}
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 83.97.87.43)
----
Manual Page -- https://php.net/manual/en/function.http-response-code.php
Edit -- https://main.php.net/note/edit/129631
Del: integrated -- https://main.php.net/note/delete/129631/integrated
Del: useless -- https://main.php.net/note/delete/129631/useless
Del: bad code -- https://main.php.net/note/delete/129631/bad+code
Del: spam -- https://main.php.net/note/delete/129631/spam
Del: non-english -- https://main.php.net/note/delete/129631/non-english
Del: in docs -- https://main.php.net/note/delete/129631/in+docs
Del: other reasons-- https://main.php.net/note/delete/129631
Reject -- https://main.php.net/note/reject/129631
Search -- https://main.php.net/manage/user-notes.php