3 * A concrete and secured HTTP request class to make HTTP requests more abstract
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
10 * @todo Move out the cookie part to a seperate class, e.g. Cookie
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class HttpRequest extends BaseRequest implements Requestable {
27 * Protected constructor
31 protected function __construct () {
32 // Call parent constructor
33 parent::__construct(__CLASS__);
37 * Creates an instance of this class and prepares it a little
39 * @return $httpInstance An instance of this class
41 public static final function createHttpRequest () {
43 $httpInstance = new HttpRequest();
45 // Prepare the HTTP request data for usage
46 $httpInstance->prepareRequestData();
48 // Return the prepared instance
53 * Prepares the HTTP request data for usage by currently copying
54 * $_REQUEST into a private attribute. Later on we can add more
55 * things for initialization here.
59 public function prepareRequestData () {
60 // Copy GET then POST data
61 $this->setRequestData(array_merge($_GET, $_POST));
65 * Getter for a header element or 'null' if header was not found
67 * @param $headerName Name of the header
68 * @return $headerValue Value of the header or 'null' if not found
70 public function getHeaderElement ($headerName) {
71 // Default return value on error
75 $name = 'HTTP_' . strtoupper($this->convertDashesToUnderscores($headerName));
77 // Does this header exist?
78 if (isset($_SERVER[$name])) {
79 $headerValue = $_SERVER[$name];
87 * Getter for request method. This getter might be useful for security filters
89 * @return $requestMethod Used request method
91 public final function getRequestMethod () {
92 return $_SERVER['REQUEST_METHOD'];
96 * Reads a cookie and returns it's value or null if not found
98 * @param $cookieName Name of cookie we shall read
99 * @return $cookieValue Value of cookie or null if not found
101 public final function readCookie ($cookieName) {
102 // Default is no cookie with that name found
105 // Is the cookie set?
106 if (isset($_COOKIE[$cookieName])) {
108 $cookieValue = $_COOKIE[$cookieName];