< – Inhaltsverzeichnis – >
Die FW_HTTP_Request Klasse ist ein Singleton, da ja nur ein Request existieren kann. Diese Klasse beinhaltet alle vom Nutzer übergebenen Informationen(header, variablen, dateien, authorisierungen) sowie die MVC Controller/Actions/Params um dem Front Controller die nötigen Infos zu geben.
/** (c) 2010 Arne "w13531" Wenzel [ mailto: w13531 (at) terrorhippiecrew (dot) net ] **/
class FW_HTTP_Request extends FW_Object {
private $post;
private $get;
private $cookie;
private $file;
private $header;
private $auth;
private $server;
private $MVC_Controller;
private $MVC_Action;
private $MVC_Action_Params;
private static $instance = null;
/**
* private clone
**/
private function __clone() {}
/**
* private constructor
**/
private function __construct() {
$this->post = &$_POST;
$this->get = &$_GET;
$this->cookie = &$_COOKIE;
$this->file = &$_FILES;
foreach($_SERVER as $key => $value) {
if(substr($key, 0, 5)== 'HTTP_') {
$key = strtolower($key); //weil es schöner aussieht
$this->header[substr($key,5)] = $value; //HTTP_ abschneiden
} else if($key != 'PHP_AUTH_USER' && $key != 'PHP_AUTH_PW') {
$key = strtolower($key);
$this->server[$key] = $value;
}
}
if(isset($_SERVER['PHP_AUTH_USER'])) {
$this->auth['user'] = $_SERVER['PHP_AUTH_USER'];
$this->auth['pass'] = $_SERVER['PHP_AUTH_PW'];
} else {
$this->auth = null;
}
}
/**
* singleton
**/
public static function getInstance() {
if(self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
/**
* sets the name of the controller
**/
public function setControllerName($name) {
$this->MVC_Controller = strtolower($name);
}
/**
* gets the name of the controller
**/
public function getControllerName() {
return $this->MVC_Controller;
}
/**
* sets the name of the action method
**/
public function setActionName($name) {
$this->MVC_Action = strtolower($name);
}
/**
* gets the name of the action method
**/
public function getActionName() {
return $this->MVC_Action;
}
/**
* sets the paramteter for the action method
**/
public function setActionParams($params) {
$this->MVC_Action_Params = $params;
}
/**
* gets the parameter for action method
**/
public function getActionParams() {
return $this->MVC_Action_Params;
}
/**
* get authentication data
**/
public function getAuthData() {
return $this->auth;
}
/**
* header information exisits
**/
public function issetHeader($key) {
$key = strtolower($key);
return (isset($this->header[$key]));
}
/**
* get header informations
**/
public function getHeader($key) {
$key = strtolower($key);
if($this->issetHeader($key)) {
return $this->header[$key];
}
return null;
}
/**
* server information exisits
**/
public function issetServer($key) {
$key = strtolower($key);
return (isset($this->server[$key]));
}
/**
* get server informations
**/
public function getServer($key) {
$key = strtolower($key);
if($this->issetServer($key)) {
return $this->server[$key];
}
return null;
}
/**
* Get var exists
**/
public function issetGet($key) {
return (isset($this->get[$key]));
}
/**
* gets Get data
**/
public function getGet($key) {
if($this->issetGet($key)) {
return $this->get[$key];
}
return null;
}
/**
* post var exists
**/
public function issetPost($key) {
return (isset($this->post[$key]));
}
/**
* gets Post data
**/
public function getPost($key) {
if($this->issetPost($key)) {
return $this->post[$key];
}
return null;
}
/**
* file exists
**/
public function issetFile($key) {
return (isset($this->file[$key]));
}
/**
* gets a file
**/
public function getFile($key) {
if($this->issetFile($key)) {
return $this->file[$key];
}
return null;
}
/**
* cookie exists
**/
public function issetCookie($key) {
return (isset($this->cookie[$key]));
}
/**
* gets cookie data
**/
public function getCookie($key) {
if($this->issetCookie($key)) {
return $this->cookie[$key];
}
return null;
}
}