|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace FastForward\Http\Message; |
| 4 | + |
| 5 | +/** |
| 6 | + * Enum StatusCode |
| 7 | + * |
| 8 | + * Defines HTTP status codes in accordance with the IETF RFC 9110 and related specifications. |
| 9 | + * This enum provides a structured representation of common HTTP response codes, grouped by their respective categories: |
| 10 | + * |
| 11 | + * - Informational (1xx) |
| 12 | + * - Successful (2xx) |
| 13 | + * - Redirection (3xx) |
| 14 | + * - Client Errors (4xx) |
| 15 | + * - Server Errors (5xx) |
| 16 | + * |
| 17 | + * All status codes MUST adhere to the official HTTP specification and SHALL be used consistently within HTTP responses. |
| 18 | + * |
| 19 | + * @package FastForward\Http\Message |
| 20 | + */ |
| 21 | +enum StatusCode: int |
| 22 | +{ |
| 23 | + // Informational 1xx |
| 24 | + |
| 25 | + /** @var int The server has received the request headers and the client SHOULD proceed to send the request body. */ |
| 26 | + case CONTINUE = 100; |
| 27 | + |
| 28 | + /** @var int The requester has asked the server to switch protocols. */ |
| 29 | + case SWITCHING_PROTOCOLS = 101; |
| 30 | + |
| 31 | + /** @var int The server has received and is processing the request, but no response is available yet. */ |
| 32 | + case PROCESSING = 102; |
| 33 | + |
| 34 | + /** @var int Used to return some response headers before the final HTTP message. */ |
| 35 | + case EARLY_HINTS = 103; |
| 36 | + |
| 37 | + // Successful 2xx |
| 38 | + |
| 39 | + /** @var int The request has succeeded. */ |
| 40 | + case OK = 200; |
| 41 | + |
| 42 | + /** @var int The request has been fulfilled and has resulted in the creation of a new resource. */ |
| 43 | + case CREATED = 201; |
| 44 | + |
| 45 | + /** @var int The request has been accepted for processing, but the processing has not been completed. */ |
| 46 | + case ACCEPTED = 202; |
| 47 | + |
| 48 | + /** @var int The request was successful, but the enclosed payload has been modified from that of the origin server. */ |
| 49 | + case NON_AUTHORITATIVE_INFORMATION = 203; |
| 50 | + |
| 51 | + /** @var int The server successfully processed the request and is not returning any content. */ |
| 52 | + case NO_CONTENT = 204; |
| 53 | + |
| 54 | + /** @var int The server successfully processed the request, but is not returning any content, and requests that the requester reset the document view. */ |
| 55 | + case RESET_CONTENT = 205; |
| 56 | + |
| 57 | + /** @var int The server is delivering only part of the resource due to a range header sent by the client. */ |
| 58 | + case PARTIAL_CONTENT = 206; |
| 59 | + |
| 60 | + /** @var int The message body that follows is an XML message and can contain a number of separate response codes. */ |
| 61 | + case MULTI_STATUS = 207; |
| 62 | + |
| 63 | + /** @var int The members of a DAV binding have already been enumerated in a previous reply to this request, and are not being included again. */ |
| 64 | + case ALREADY_REPORTED = 208; |
| 65 | + |
| 66 | + /** @var int The server has fulfilled a request for the resource, and the response is a representation of the result of one or more instance-manipulations. */ |
| 67 | + case IM_USED = 226; |
| 68 | + |
| 69 | + // Redirection 3xx |
| 70 | + |
| 71 | + /** @var int Indicates multiple options for the resource from which the client may choose. */ |
| 72 | + case MULTIPLE_CHOICES = 300; |
| 73 | + |
| 74 | + /** @var int This and all future requests SHOULD be directed to the given URI. */ |
| 75 | + case MOVED_PERMANENTLY = 301; |
| 76 | + |
| 77 | + /** @var int The resource resides temporarily under a different URI. */ |
| 78 | + case FOUND = 302; |
| 79 | + |
| 80 | + /** @var int The response to the request can be found under another URI using a GET method. */ |
| 81 | + case SEE_OTHER = 303; |
| 82 | + |
| 83 | + /** @var int Indicates the resource has not been modified since the version specified by the request headers. */ |
| 84 | + case NOT_MODIFIED = 304; |
| 85 | + |
| 86 | + /** @var int The requested resource is only available through a proxy, whose address is provided in the response. */ |
| 87 | + case USE_PROXY = 305; |
| 88 | + |
| 89 | + /** @var int Reserved for future use. */ |
| 90 | + case RESERVED = 306; |
| 91 | + |
| 92 | + /** @var int Instructs the client to repeat the request with a different URI. */ |
| 93 | + case TEMPORARY_REDIRECT = 307; |
| 94 | + |
| 95 | + /** @var int The request and all future requests SHOULD be repeated using another URI. */ |
| 96 | + case PERMANENT_REDIRECT = 308; |
| 97 | + |
| 98 | + // Client Errors 4xx |
| 99 | + |
| 100 | + /** @var int The server cannot process the request due to a client error. */ |
| 101 | + case BAD_REQUEST = 400; |
| 102 | + |
| 103 | + /** @var int Authentication is required and has failed or has not yet been provided. */ |
| 104 | + case UNAUTHORIZED = 401; |
| 105 | + |
| 106 | + /** @var int Payment is required to access the requested resource. */ |
| 107 | + case PAYMENT_REQUIRED = 402; |
| 108 | + |
| 109 | + /** @var int The client does not have permission to access the resource. */ |
| 110 | + case FORBIDDEN = 403; |
| 111 | + |
| 112 | + /** @var int The requested resource could not be found. */ |
| 113 | + case NOT_FOUND = 404; |
| 114 | + |
| 115 | + /** @var int A request method is not supported for the requested resource. */ |
| 116 | + case METHOD_NOT_ALLOWED = 405; |
| 117 | + |
| 118 | + /** @var int The requested resource is capable of generating only content not acceptable according to the Accept headers. */ |
| 119 | + case NOT_ACCEPTABLE = 406; |
| 120 | + |
| 121 | + /** @var int Proxy authentication is required to access the resource. */ |
| 122 | + case PROXY_AUTHENTICATION_REQUIRED = 407; |
| 123 | + |
| 124 | + /** @var int The client did not produce a request within the time that the server was prepared to wait. */ |
| 125 | + case REQUEST_TIMEOUT = 408; |
| 126 | + |
| 127 | + /** @var int The request could not be completed due to a conflict with the current state of the resource. */ |
| 128 | + case CONFLICT = 409; |
| 129 | + |
| 130 | + /** @var int The resource requested is no longer available and will not be available again. */ |
| 131 | + case GONE = 410; |
| 132 | + |
| 133 | + /** @var int The request did not specify the length of its content, which is required by the requested resource. */ |
| 134 | + case LENGTH_REQUIRED = 411; |
| 135 | + |
| 136 | + /** @var int The server does not meet one of the preconditions specified by the requester. */ |
| 137 | + case PRECONDITION_FAILED = 412; |
| 138 | + |
| 139 | + /** @var int The request is larger than the server is willing or able to process. */ |
| 140 | + case PAYLOAD_TOO_LARGE = 413; |
| 141 | + |
| 142 | + /** @var int The URI provided was too long for the server to process. */ |
| 143 | + case URI_TOO_LONG = 414; |
| 144 | + |
| 145 | + /** @var int The server does not support the media format of the requested data. */ |
| 146 | + case UNSUPPORTED_MEDIA_TYPE = 415; |
| 147 | + |
| 148 | + /** @var int The client has asked for a portion of the file, but the server cannot supply that portion. */ |
| 149 | + case RANGE_NOT_SATISFIABLE = 416; |
| 150 | + |
| 151 | + /** @var int The server cannot meet the expectations specified in the Expect request header. */ |
| 152 | + case EXPECTATION_FAILED = 417; |
| 153 | + |
| 154 | + /** @var int This code is returned by HTCPCP-compliant teapots. */ |
| 155 | + case IM_A_TEAPOT = 418; |
| 156 | + |
| 157 | + /** @var int The request was directed at a server that is not able to produce a response. */ |
| 158 | + case MISDIRECTED_REQUEST = 421; |
| 159 | + |
| 160 | + /** @var int The request was well-formed but was unable to be followed due to semantic errors. */ |
| 161 | + case UNPROCESSABLE_ENTITY = 422; |
| 162 | + |
| 163 | + /** @var int The resource that is being accessed is locked. */ |
| 164 | + case LOCKED = 423; |
| 165 | + |
| 166 | + /** @var int The request failed due to failure of a previous request. */ |
| 167 | + case FAILED_DEPENDENCY = 424; |
| 168 | + |
| 169 | + /** @var int Indicates the server is unwilling to risk processing a request that might be replayed. */ |
| 170 | + case TOO_EARLY = 425; |
| 171 | + |
| 172 | + /** @var int The client should switch to a different protocol such as TLS/1.0. */ |
| 173 | + case UPGRADE_REQUIRED = 426; |
| 174 | + |
| 175 | + /** @var int The origin server requires the request to be conditional. */ |
| 176 | + case PRECONDITION_REQUIRED = 428; |
| 177 | + |
| 178 | + /** @var int The user has sent too many requests in a given amount of time. */ |
| 179 | + case TOO_MANY_REQUESTS = 429; |
| 180 | + |
| 181 | + /** @var int The server is unwilling to process the request because its header fields are too large. */ |
| 182 | + case REQUEST_HEADER_FIELDS_TOO_LARGE = 431; |
| 183 | + |
| 184 | + /** @var int The requested resource is unavailable for legal reasons. */ |
| 185 | + case UNAVAILABLE_FOR_LEGAL_REASONS = 451; |
| 186 | + |
| 187 | + // Server Errors 5xx |
| 188 | + |
| 189 | + /** @var int The server encountered an unexpected condition that prevented it from fulfilling the request. */ |
| 190 | + case INTERNAL_SERVER_ERROR = 500; |
| 191 | + |
| 192 | + /** @var int The server does not support the functionality required to fulfill the request. */ |
| 193 | + case NOT_IMPLEMENTED = 501; |
| 194 | + |
| 195 | + /** @var int The server, while acting as a gateway or proxy, received an invalid response from the upstream server. */ |
| 196 | + case BAD_GATEWAY = 502; |
| 197 | + |
| 198 | + /** @var int The server is currently unavailable due to maintenance or overload. */ |
| 199 | + case SERVICE_UNAVAILABLE = 503; |
| 200 | + |
| 201 | + /** @var int The server did not receive a timely response from an upstream server. */ |
| 202 | + case GATEWAY_TIMEOUT = 504; |
| 203 | + |
| 204 | + /** @var int The server does not support the HTTP protocol version used in the request. */ |
| 205 | + case VERSION_NOT_SUPPORTED = 505; |
| 206 | + |
| 207 | + /** @var int Transparent content negotiation for the request results in a circular reference. */ |
| 208 | + case VARIANT_ALSO_NEGOTIATES = 506; |
| 209 | + |
| 210 | + /** @var int The server is unable to store the representation needed to complete the request. */ |
| 211 | + case INSUFFICIENT_STORAGE = 507; |
| 212 | + |
| 213 | + /** @var int The server detected an infinite loop while processing a request. */ |
| 214 | + case LOOP_DETECTED = 508; |
| 215 | + |
| 216 | + /** @var int Further extensions to the request are required for the server to fulfill it. */ |
| 217 | + case NOT_EXTENDED = 510; |
| 218 | + |
| 219 | + /** @var int The client needs to authenticate to gain network access. */ |
| 220 | + case NETWORK_AUTHENTICATION_REQUIRED = 511; |
| 221 | + |
| 222 | + /** |
| 223 | + * Returns a human-readable description of the status code. |
| 224 | + * |
| 225 | + * The description is derived from the enum name, replacing underscores with spaces and capitalizing each word. |
| 226 | + * |
| 227 | + * @return string The reason phrase corresponding to the status code. |
| 228 | + */ |
| 229 | + public function reasonPhrase(): string |
| 230 | + { |
| 231 | + $phrase = str_replace('_', ' ', strtolower($this->name)); |
| 232 | + |
| 233 | + return ucwords($phrase); |
| 234 | + } |
| 235 | +} |
0 commit comments