1 | <?php |
||
37 | class StatusLine |
||
38 | { |
||
39 | /** |
||
40 | * The actual response code. |
||
41 | * |
||
42 | * @var int |
||
43 | */ |
||
44 | private $code; |
||
45 | |||
46 | /** |
||
47 | * The reason phrase. |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | private $reason; |
||
52 | |||
53 | /** |
||
54 | * Constructor. |
||
55 | * |
||
56 | * @param int $code The response code |
||
57 | * @param string $reason The reason phrase |
||
58 | */ |
||
59 | final public function __construct($code, $reason) |
||
64 | |||
65 | /** |
||
66 | * Return the response code. |
||
67 | * |
||
68 | * @return int |
||
69 | */ |
||
70 | final public function code() |
||
74 | |||
75 | /** |
||
76 | * Return the reason phrase |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | final public function reason() |
||
84 | |||
85 | /** |
||
86 | * Add the status code and reason phrase to a Response. |
||
87 | * |
||
88 | * @param ResponseInterface $response The response |
||
89 | * @return ResponseInterface |
||
90 | */ |
||
91 | public function response(ResponseInterface $response) |
||
95 | |||
96 | /** |
||
97 | * Return the status class of the response code. |
||
98 | * |
||
99 | * @return int |
||
100 | */ |
||
101 | final public function responseClass() |
||
105 | |||
106 | /** |
||
107 | * Helper to establish if the class of the status code |
||
108 | * is informational (1xx). |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | final public function isInformational() |
||
116 | |||
117 | /** |
||
118 | * Helper to establish if the class of the status code |
||
119 | * is successful (2xx). |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | final public function isSuccessful() |
||
127 | |||
128 | /** |
||
129 | * Helper to establish if the class of the status code |
||
130 | * is redirection (3xx). |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | final public function isRedirection() |
||
138 | |||
139 | /** |
||
140 | * Helper to establish if the class of the status code |
||
141 | * is client error (4xx). |
||
142 | * |
||
143 | * @return bool |
||
144 | */ |
||
145 | final public function isClientError() |
||
149 | |||
150 | /** |
||
151 | * Helper to establish if the class of the status code |
||
152 | * is server error (5xx). |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | final public function isServerError() |
||
160 | |||
161 | /** |
||
162 | * Set the code. Used in constructor to ensure the code meets the |
||
163 | * requirements for a status code. |
||
164 | * |
||
165 | * @param int $code The status code |
||
166 | * @throws InvalidStatusCodeException If the status code is invalid |
||
167 | */ |
||
168 | private function setCode($code) |
||
186 | |||
187 | /** |
||
188 | * Test whether the response class matches the class passed to it. |
||
189 | * |
||
190 | * @param int $class The class of the response code |
||
191 | * @return bool |
||
192 | */ |
||
193 | private function is($class) |
||
197 | } |
||
198 |
Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.