RequestResponse
[ class tree: RequestResponse ] [ index: RequestResponse ] [ all elements ]

Source for file HttpResponse.php

Documentation is available at HttpResponse.php

  1. <?php
  2. /**
  3.  * MVClasses
  4.  *
  5.  * LICENSE
  6.  *
  7.  * "THE BEER-WARE LICENSE" (Revision 42):
  8.  * "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
  9.  * As long as you retain this notice you can do whatever you want with
  10.  * this stuff. If we meet some day, and you think this stuff is worth it,
  11.  * you can buy me a beer in return.
  12.  *
  13.  * @category    MVClasses
  14.  * @package     RequestResponse
  15.  * @copyright   Copyright (c) 2007 Sven Strittmatter
  16.  */
  17.  
  18. /**
  19.  * @see Response
  20.  */
  21. require_once dirname(__FILE__)."/../Response.php";
  22. /**
  23.  * @see GenerallHttpHeaders
  24.  */
  25. require_once dirname(__FILE__)."/GenerallHttpHeaders.php";
  26.  
  27. /**
  28.  * Enter description here...
  29.  *
  30.  * Longdesc
  31.  *
  32.  * @todo complete description
  33.  *
  34.  * @category    MVClasses
  35.  * @package     RequestResponse
  36.  * @copyright     Copyright (c) 2007 Sven Strittmatter
  37.  * @author    "Sven Strittmatter" <ausserirdisch@sven-space.de>
  38.  * @version     1.0
  39.  * @link        http://www.sven-space.de/code/php/MVClasses
  40.  */
  41. class HttpResponse implements ResponseGenerallHttpHeaders {
  42.     // Information:
  43.     const HTTP_STATUS_100 "100 Continue";
  44.     const HTTP_STATUS_101 "101 Switching Protocols";
  45.     const HTTP_STATUS_102 "102 Processing";
  46.     // Succesfull operations:
  47.     const HTTP_STATUS_200 "200 OK";
  48.     const HTTP_STATUS_201 "201 Created";
  49.     const HTTP_STATUS_202 "202 Accepted";
  50.     const HTTP_STATUS_203 "203 Non-Authoritative Information";
  51.     const HTTP_STATUS_204 "204 No Content";
  52.     const HTTP_STATUS_205 "205 Reset Content";
  53.     const HTTP_STATUS_206 "206 Partial Content";
  54.     const HTTP_STATUS_207 "207 Multi-Status";
  55.     // Redirection:
  56.     const HTTP_STATUS_300 "300 Multiple Choice";
  57.     const HTTP_STATUS_301 "301 Moved Permanently";
  58.     const HTTP_STATUS_302 "302 Found";
  59.     const HTTP_STATUS_303 "303 See Other";
  60.     const HTTP_STATUS_304 "304 Not Modified";
  61.     const HTTP_STATUS_305 "305 Use Proxy";
  62.     const HTTP_STATUS_307 "307 Temporary Redirect";
  63.     // Client errors:
  64.     const HTTP_STATUS_400 "400 Bad Request";
  65.     const HTTP_STATUS_401 "401 Unauthorized";
  66.     const HTTP_STATUS_402 "402 Payment Required";
  67.     const HTTP_STATUS_403 "403 Forbidden";
  68.     const HTTP_STATUS_404 "404 Not Found";
  69.     const HTTP_STATUS_405 "405 Method Not Allowed";
  70.     const HTTP_STATUS_406 "406 Not Acceptable";
  71.     const HTTP_STATUS_407 "407 Proxy Authentication Required";
  72.     const HTTP_STATUS_408 "408 Request Time-out";
  73.     const HTTP_STATUS_409 "409 Conflict";
  74.     const HTTP_STATUS_410 "410 Gone";
  75.     const HTTP_STATUS_411 "411 Length Required";
  76.     const HTTP_STATUS_412 "412 Precondition Failed";
  77.     const HTTP_STATUS_413 "413 Request Entity Too Large";
  78.     const HTTP_STATUS_414 "414 Request-URI Too Long";
  79.     const HTTP_STATUS_415 "415 Unsupported Media Type";
  80.     const HTTP_STATUS_416 "416 Requested range not satisfiable";
  81.     const HTTP_STATUS_417 "417 Expectation Failed";
  82.     const HTTP_STATUS_422 "422 Unprocessable Entity";
  83.     const HTTP_STATUS_423 "423 Locked";
  84.     const HTTP_STATUS_424 "424 Failed Dependency";
  85.     // Server errors
  86.     const HTTP_STATUS_500 "500 Internal Server Error";
  87.     const HTTP_STATUS_501 "501 Not Implemented";
  88.     const HTTP_STATUS_502 "502 Bad Gateway";
  89.     const HTTP_STATUS_503 "503 Service Unavailable";
  90.     const HTTP_STATUS_504 "504 Gateway Time-out";
  91.     const HTTP_STATUS_505 "505 HTTP Version not supported";
  92.     const HTTP_STATUS_507 "507 Insufficient Storage";
  93.     const HTTP_STATUS_509 "509 Bandwidth Limit Exceeded";
  94.  
  95.     // konstanten fuer headers (http://www.bolege.de/http-header/#art2)
  96.     const HTTP_HEADER_AGE "Age";
  97.     const HTTP_HEADER_ETAG "ETag";
  98.     const HTTP_HEADER_LOCATION "Location";
  99.     const HTTP_HEADER_PROXY_AUTHENITACION "Proxy-Authenticate";
  100.     const HTTP_HEADER_SET_COOKIE "Set-cookie";
  101.     const HTTP_HEADER_CONTENT_TYPE "Content-Type";
  102.     const HTTP_HEADER_SERVER "Server";
  103.     const HTTP_HEADER_RETRY_AFTER "Retry-after";
  104.  
  105.     private $_status;
  106.     private $_headers;
  107.     private $_body;
  108.  
  109.     public function __construct({
  110.         $this->_status self::HTTP_STATUS_200;
  111.         $this->_headers array();
  112.         $this->_body null;
  113.     }
  114.  
  115.     public function setStatus($status{
  116.         $this->_status $status;
  117.     }
  118.  
  119.     public function addHeader($name$value{
  120.         $this->_headers[$name$value;
  121.     }
  122.  
  123.     public function write($data{
  124.         $this->_body .= $data;
  125.     }
  126.  
  127.     public function flush({
  128.         header("HTTP/1.1 {$this->_status}");
  129.  
  130.         foreach ($this->_headers as $name => $value{
  131.             header("{$name}: {$value}");
  132.         }
  133.  
  134.         print $this->_body;
  135.         $this->_headers array();
  136.         $this->_body null;
  137.     }
  138.  
  139.     public function getBody() {
  140.         return $this->_body;
  141.     }
  142.  
  143.     public function setBody($body) {
  144.         $this->_body $body;
  145.     }
  146. }

Documentation generated on Sun, 02 Aug 2009 17:15:01 +0200 by phpDocumentor 1.4.2