-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from bowphp/fix/str
Implement feature for improve http and str classes
- Loading branch information
Showing
4 changed files
with
157 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
|
||
namespace Bow\Http; | ||
|
||
use InvalidArgumentException; | ||
|
||
final class HttpStatus | ||
{ | ||
private const STATUS = [ | ||
100 => 'Continue', | ||
101 => 'Switching Protocols', | ||
102 => 'Processing', | ||
200 => 'OK', | ||
201 => 'Created', | ||
202 => 'Accepted', | ||
204 => 'No Content', | ||
205 => 'Reset Content', | ||
206 => 'Partial Content', | ||
207 => 'Multi-Status', | ||
208 => 'Already Reported', | ||
226 => 'IM Used', | ||
300 => 'Multipe Choices', | ||
301 => 'Moved Permanently', | ||
302 => 'Found', | ||
303 => 'See Other', | ||
304 => 'Not Modified', | ||
305 => 'Use Proxy', | ||
307 => 'Temporary Redirect', | ||
308 => 'Permanent Redirect', | ||
400 => 'Bad Request', | ||
401 => 'Unauthorized', | ||
402 => 'Payment Required', | ||
403 => 'Forbidden', | ||
404 => 'Not Found', | ||
405 => 'Method Not Allowed', | ||
406 => 'Not Acceptable', | ||
407 => 'Proxy Authentication', | ||
408 => 'Request Time Out', | ||
409 => 'Conflict', | ||
410 => 'Gone', | ||
411 => 'Length Required', | ||
412 => 'Precondition Failed', | ||
413 => 'Payload Too Large', | ||
414 => 'URI Too Long', | ||
415 => 'Unsupport Media', | ||
416 => 'Range Not Statisfiable', | ||
417 => 'Expectation Failed', | ||
418 => 'I\'m a teapot', | ||
421 => 'Misdirected Request', | ||
422 => 'Unprocessable Entity', | ||
423 => 'Locked', | ||
424 => 'Failed Dependency', | ||
426 => 'Upgrade Required', | ||
428 => 'Precondition Required', | ||
429 => 'Too Many Requests', | ||
431 => 'Request Header Fields Too Large', | ||
444 => 'Connection Closed Without Response', | ||
451 => 'Unavailable For Legal Reasons', | ||
499 => 'Client Closed Request', | ||
500 => 'Internal Server Error', | ||
501 => 'Not Implemented', | ||
502 => 'Bad Gateway', | ||
503 => 'Service Unavailable', | ||
504 => 'Gateway Timeout', | ||
505 => 'HTTP Version Not Supported', | ||
]; | ||
|
||
public const CONTINUE = 100; | ||
public const SWITCHING_PROTOCOLS = 101; | ||
public const PROCESSING = 102; | ||
public const OK = 200; | ||
public const CREATED = 201; | ||
public const ACCEPTED = 202; | ||
public const NO_CONTENT = 204; | ||
public const RESET_CONTENT = 205; | ||
public const PARTIAL_CONTENT = 206; | ||
public const MULTI_STATUS = 207; | ||
public const ALREADY_REPORTED = 208; | ||
public const IM_USED = 226; | ||
public const MULTIPE_CHOICES = 300; | ||
public const MOVED_PERMANENTLY = 301; | ||
public const FOUND_ = 302; | ||
public const SEE_OTHER = 303; | ||
public const NOT_MODIFIED = 304; | ||
public const USE_PROXY = 305; | ||
public const TEMPORARY_REDIRECT = 307; | ||
public const PERMANENT_REDIRECT = 308; | ||
public const BAD_REQUEST = 400; | ||
public const UNAUTHORIZED_ = 401; | ||
public const PAYMENT_REQUIRED = 402; | ||
public const FORBIDDEN_ = 403; | ||
public const NOT_FOUND = 404; | ||
public const METHOD_NOT_ALLOWED = 405; | ||
public const NOT_ACCEPTABLE = 406; | ||
public const PROXY_AUTHENTICATION = 407; | ||
public const REQUEST_TIME_OUT = 408; | ||
public const CONFLICT_ = 409; | ||
public const GONE_ = 410; | ||
public const LENGTH_REQUIRED = 411; | ||
public const PRECONDITION_FAILED = 412; | ||
public const PAYLOAD_TOO_LARGE = 413; | ||
public const URI_TOO_LONG = 414; | ||
public const UNSUPPORT_MEDIA = 415; | ||
public const RANGE_NOT_STATISFIABLE = 416; | ||
public const EXPECTATION_FAILED = 417; | ||
public const I_M_A_TEAPOT = 418; | ||
public const MISDIRECTED_REQUEST = 421; | ||
public const UNPROCESSABLE_ENTITY = 422; | ||
public const LOCKED_ = 423; | ||
public const FAILED_DEPENDENCY = 424; | ||
public const UPGRADE_REQUIRED = 426; | ||
public const PRECONDITION_REQUIRED = 428; | ||
public const TOO_MANY_REQUESTS = 429; | ||
public const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; | ||
public const CONNECTION_CLOSED_WITHOUT_RESPONSE = 444; | ||
public const UNAVAILABLE_FOR_LEGAL_REASONS = 451; | ||
public const CLIENT_CLOSED_REQUEST = 499; | ||
public const INTERNAL_SERVER_ERROR = 500; | ||
public const NOT_IMPLEMENTED = 501; | ||
public const BAD_GATEWAY = 502; | ||
public const SERVICE_UNAVAILABLE = 503; | ||
public const GATEWAY_TIMEOUT = 504; | ||
public const HTTP_VERSION_NOT_SUPPORTED = 505; | ||
|
||
/** | ||
* Get the message | ||
* | ||
* @param int $code | ||
* @return string | ||
*/ | ||
public static function getMessage(int $code): string | ||
{ | ||
if (!isset(static::STATUS[$code])) { | ||
throw new InvalidArgumentException("The code {$code} is not exists"); | ||
} | ||
|
||
return static::STATUS[$code]; | ||
} | ||
|
||
/** | ||
* Get the codes | ||
* | ||
* @return array | ||
*/ | ||
public static function getCodes(): array | ||
{ | ||
return array_keys(static::STATUS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters