1 | <?php |
||
14 | class HttpStatus |
||
15 | { |
||
16 | |||
17 | const STATUS_200 = 'OK'; |
||
18 | |||
19 | const STATUS_301 = 'Moved Permanently'; |
||
20 | |||
21 | const STATUS_302 = 'Found'; |
||
22 | |||
23 | const STATUS_400 = 'Bad Request'; |
||
24 | |||
25 | const STATUS_401 = 'Unauthorized'; |
||
26 | |||
27 | const STATUS_403 = 'Forbidden'; |
||
28 | |||
29 | const STATUS_404 = 'Not Found'; |
||
30 | |||
31 | const STATUS_500 = 'Internal Server Error'; |
||
32 | |||
33 | const STATUS_501 = 'Not Implemented'; |
||
34 | |||
35 | const STATUS_502 = 'Bad Gateway'; |
||
36 | |||
37 | const STATUS_503 = 'Service Unavailable'; |
||
38 | |||
39 | const STATUS_505 = 'HTTP Version Not Supported'; |
||
40 | |||
41 | /** |
||
42 | * The status code |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | private $code; |
||
47 | |||
48 | /** |
||
49 | * The protocol version |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $proto; |
||
54 | |||
55 | /** |
||
56 | * Create a new HttpStatus instance |
||
57 | * |
||
58 | * @param int $code |
||
59 | * The status code |
||
60 | * @param string $protocolVersion |
||
61 | * The version of Http protocol (e.g. 1.0) |
||
62 | */ |
||
63 | 19 | public function __construct($code, $protocolVersion = '1.1') |
|
68 | |||
69 | /** |
||
70 | * Retrieve the status message for a particular code |
||
71 | * |
||
72 | * @param int $code |
||
73 | * |
||
74 | * @return string The status message |
||
75 | */ |
||
76 | 2 | public static function getStatus($code): string |
|
81 | |||
82 | /** |
||
83 | * Parse the status line into its parts |
||
84 | * |
||
85 | * @param string $statusLine |
||
86 | * |
||
87 | * @return HttpStatus |
||
88 | */ |
||
89 | 19 | public static function parseStatus($statusLine): HttpStatus |
|
94 | |||
95 | /** |
||
96 | * Retrieve the status line |
||
97 | * |
||
98 | * @return string The status line according RFC |
||
99 | * @see http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p1-messaging-latest.html#rfc.section.3.1.2 |
||
100 | */ |
||
101 | 1 | public function toStatusLine(): string |
|
105 | |||
106 | /** |
||
107 | * Retrieve the status as string |
||
108 | * It is a wrapper for |
||
109 | * |
||
110 | * @see \Generics\Client\HttpStatus::toStatusLine() |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 1 | public function __toString(): string |
|
118 | |||
119 | /** |
||
120 | * Get the status code |
||
121 | * |
||
122 | * @return int |
||
123 | */ |
||
124 | 19 | public function getCode(): int |
|
128 | |||
129 | /** |
||
130 | * Get the protocol including version |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | 1 | public function getProtocol(): string |
|
138 | } |
||
139 |