* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @todo Move out the cookie part to a seperate class, e.g. Cookie * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class HttpRequest extends BaseRequest implements Requestable { /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Creates an instance of this class and prepares it a little * * @return $httpInstance An instance of this class */ public static final function createHttpRequest () { // Create an instance $httpInstance = new HttpRequest(); // Prepare the HTTP request data for usage $httpInstance->prepareRequestData(); // Return the prepared instance return $httpInstance; } /** * Prepares the HTTP request data for usage by currently copying * $_REQUEST into a private attribute. Later on we can add more * things for initialization here. * * @return void */ public function prepareRequestData () { // Copy GET then POST data $this->setRequestData(array_merge($_GET, $_POST)); } /** * Getter for a header element or 'null' if header was not found * * @param $headerName Name of the header * @return $headerValue Value of the header or 'null' if not found */ public function getHeader ($headerName) { // Default return value on error $headerValue = NULL; // Construct the name $name = 'HTTP_' . strtolower($this->convertDashesToUnderscores($headerName)); // Does this header exist? if (isset($_SERVER[$name])) { $headerValue = $_SERVER[$name]; } // END - if // Return the value return $headerValue; } /** * Getter for request method. This getter might be useful for security filters * * @return $requestMethod Used request method */ public final function getRequestMethod () { return $_SERVER['REQUEST_METHOD']; } /** * Reads a cookie and returns it's value or null if not found * * @param $cookieName Name of cookie we shall read * @return $cookieValue Value of cookie or null if not found */ public final function readCookie ($cookieName) { // Default is no cookie with that name found $cookieValue = NULL; // Is the cookie set? if (isset($_COOKIE[$cookieName])) { // Then get it $cookieValue = $_COOKIE[$cookieName]; } // END - if // Return the value return $cookieValue; } } // [EOF] ?>