| | 45 | * Since 3.1.2, HTTP status code can be set with the {@link setStatusCode StatusCode} property. |
| | 46 | * |
| | 47 | * Note: Some HTTP Status codes can require additional header or body information. So, if you use {@link setStatusCode StatusCode} |
| | 48 | * in your application, be sure to add theses informations. |
| | 49 | * E.g : to make an http authentication : |
| | 50 | * <code> |
| | 51 | * public function clickAuth ($sender, $param) |
| | 52 | * { |
| | 53 | * $response=$this->getResponse(); |
| | 54 | * $response->setStatusCode(401); |
| | 55 | * $response->appendHeader('WWW-Authenticate: Basic realm="Test"'); |
| | 56 | * } |
| | 57 | * </code> |
| | 58 | * |
| | 59 | * This event handler will sent the 401 status code (Unauthorized) to the browser, with the WWW-Authenticate header field. This |
| | 60 | * will force the browser to ask for a username and a password. |
| | 61 | * |
| | 70 | * @var The differents defined status code by RFC 2616 {@link http://www.faqs.org/rfcs/rfc2616} |
| | 71 | */ |
| | 72 | private static $HTTP_STATUS_CODES = array( |
| | 73 | 100 => 'Continue', 101 => 'Switching Protocols', |
| | 74 | 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', |
| | 75 | 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', |
| | 76 | 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', |
| | 77 | 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported' |
| | 78 | ); |
| | 79 | |
| | 80 | /** |
| 229 | | public function setStatusCode($status) |
| 230 | | { |
| 231 | | $this->_status=TPropertyValue::ensureInteger($status); |
| | 263 | public function setStatusCode($status, $reason=null) |
| | 264 | { |
| | 265 | $status=TPropertyValue::ensureInteger($status); |
| | 266 | if(isset(self::$HTTP_STATUS_CODES[$status])) { |
| | 267 | $this->_reason=self::$HTTP_STATUS_CODES[$status]; |
| | 268 | }else{ |
| | 269 | if($reason===null || $reason==='') { |
| | 270 | throw new TInvalidDataValueException("response_status_reason_missing"); |
| | 271 | } |
| | 272 | $reason=TPropertyValue::ensureString($reason); |
| | 273 | if(strpos($reason, "\r")!=false || strpos($reason, "\n")!=false) { |
| | 274 | throw new TInvalidDataValueException("response_status_reason_barchars"); |
| | 275 | } |
| | 276 | $this->_reason=$reason; |
| | 277 | } |
| | 278 | $this->_status=$status; |
| | 279 | } |
| | 280 | |
| | 281 | /** |
| | 282 | * @param string HTTP status reason |
| | 283 | */ |
| | 284 | public function getStatusReason() { |
| | 285 | return $this->_reason; |