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

Source for file HttpRequest.php

Documentation is available at HttpRequest.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 Request
  20.  */
  21. require_once dirname(__FILE__)."/../Request.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 HttpRequest implements Request, GenerallHttpHeaders {
  42. // Konstanten fuer den parameter type.
  43.     const GLOBALS_POST = "post";
  44.     const GLOBALS_GET = "get";
  45.  
  46.     // konstanten fuer headers (http://www.bolege.de/http-header/#art2)
  47.     const HTTP_HEADER_ACCEPT = "Accept";
  48.     const HTTP_HEADER_ACCEPT_ENCODING = "Accept-Encoding";
  49.     const HTTP_HEADER_AUTHORIZATION = "Authorization";
  50.     const HTTP_HEADER_COOKIE = "Cookie";
  51.     const HTTP_HEADER_HOST = "Host";
  52.     const HTTP_HEADER_IF_MODIFIED_SINCE = "If-Modified-Since";
  53.     const HTTP_HEADER_PROXY_AUTHORIZATION = "Proxy-Authorization";
  54.     const HTTP_HEADER_RANGE = "Range";
  55.     const HTTP_HEADER_REFERER = "Referer";
  56.     const HTTP_HEADER_USER_AGENT = "User-Agent";
  57.  
  58.     private $_parameters;
  59.  
  60.     public function __construct() {
  61.         $this->_parameters[self::GLOBALS_POST] = $_POST;
  62.         $this->_parameters[self::GLOBALS_GET] = $_GET;
  63.     }
  64.  
  65.     public function getParameterNames($type = null) {
  66.         if (null === $type) {
  67.             return array_merge(
  68.             array_keys($this->_parameters[self::GLOBALS_POST]),
  69.             array_keys($this->_parameters[self::GLOBALS_GET]));
  70.         } else {
  71.             return array_keys($this->_parameters[$type]);
  72.         }
  73.     }
  74.  
  75.     public function issetParameter($name, $type = self::GLOBALS_GET) {
  76.         switch ($type) {
  77.             case self::GLOBALS_GET:
  78.                 return isset($this->_parameters[self::GLOBALS_GET][$name]);
  79.                 break;
  80.             case self::GLOBALS_POST:
  81.                 return isset($this->_parameters[self::GLOBALS_POST ][$name]);
  82.                 break;
  83.         }
  84.     }
  85.  
  86.     public function getParameter($name, $type = self::GLOBALS_GET) {
  87.         if ($this->issetParameter($name, $type)) {
  88.             return $this->_parameters[$type][$name];
  89.         }
  90.  
  91.         return null;
  92.     }
  93.  
  94.     public function getHeader($name) {
  95.         $name = "HTTP_" . strtoupper(str_replace("-", "_", $name));
  96.  
  97.         if (isset($_SERVER[$name])) {
  98.             return $_SERVER[$name];
  99.         }
  100.  
  101.         return null;
  102.     }
  103.  
  104.     public function getAuthData() {
  105.         if (!isset($_SERVER['PHP_AUTH_USER'])) {
  106.             return null;
  107.         }
  108.  
  109.         return array(
  110.         'username'        => $_SERVER['PHP_AUTH_USER'],
  111.         'password'    => $_SERVER['PHP_AUTH_PW']
  112.         );
  113.     }
  114.  
  115.     public function getRemoteAddress() {
  116.         return $_SERVER['REMOTE_ADDR'];
  117.     }
  118. }

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