11use InvalidArgumentException;
21 private static $headersSentCallback =
null;
24 $old = self::$headersSentCallback;
25 self::$headersSentCallback = $callback;
37 static $statusMessage = [
39 101 =>
'Switching Protocols',
44 203 =>
'Non-Authoritative Information',
46 205 =>
'Reset Content',
47 206 =>
'Partial Content',
48 207 =>
'Multi-Status',
49 300 =>
'Multiple Choices',
50 301 =>
'Moved Permanently',
53 304 =>
'Not Modified',
55 307 =>
'Temporary Redirect',
57 401 =>
'Unauthorized',
58 402 =>
'Payment Required',
61 405 =>
'Method Not Allowed',
62 406 =>
'Not Acceptable',
63 407 =>
'Proxy Authentication Required',
64 408 =>
'Request Timeout',
67 411 =>
'Length Required',
68 412 =>
'Precondition Failed',
69 413 =>
'Request Entity Too Large',
70 414 =>
'Request-URI Too Large',
71 415 =>
'Unsupported Media Type',
72 416 =>
'Request Range Not Satisfiable',
73 417 =>
'Expectation Failed',
74 422 =>
'Unprocessable Entity',
76 424 =>
'Failed Dependency',
77 428 =>
'Precondition Required',
78 429 =>
'Too Many Requests',
79 431 =>
'Request Header Fields Too Large',
80 500 =>
'Internal Server Error',
81 501 =>
'Not Implemented',
83 503 =>
'Service Unavailable',
84 504 =>
'Gateway Timeout',
85 505 =>
'HTTP Version Not Supported',
86 507 =>
'Insufficient Storage',
87 511 =>
'Network Authentication Required',
89 return $statusMessage[$code] ??
null;
100 static $version = null;
101 $message = self::getMessage( $code );
102 if ( $message ===
null ) {
103 throw new InvalidArgumentException(
"Unknown HTTP status code $code" );
106 if ( $version ===
null ) {
107 $version = isset( $_SERVER[
'SERVER_PROTOCOL'] ) &&
108 $_SERVER[
'SERVER_PROTOCOL'] ===
'HTTP/1.0' ?
113 return "HTTP/$version $code $message";
123 if ( headers_sent() ) {
124 if ( self::$headersSentCallback ) {
125 ( self::$headersSentCallback )();
134 header( self::getHeader( $code ) );
135 }
catch ( InvalidArgumentException ) {
136 trigger_error(
"Unknown HTTP status code $code", E_USER_WARNING );
143class_alias( HttpStatus::class,
'HttpStatus' );