3 * A concrete and secured HTML request class to make HTML requests more abstract
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HtmlRequest 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 $requestInstance An instance of this class
41 public static final function createHtmlRequest () {
43 $requestInstance = new HtmlRequest();
45 // Prepare the HTML request data for usage
46 $requestInstance->prepareRequestData();
48 // Return the prepared instance
49 return $requestInstance;
53 * Checks if the request method is GET.
55 * @return $isGet Whether the request method is GET
57 public function isGetRequestMethod () {
59 return ($this->getRequestMethod() == 'GET');
63 * Checks if the request method is HEAD.
65 * @return $isHead Whether the request method is HEAD
67 public function isHeadRequestMethod () {
69 return ($this->getRequestMethod() == 'HEAD');
73 * Checks if the request method is POST.
75 * @return $isPost Whether the request method is POST
77 public function isPostRequestMethod () {
79 return ($this->getRequestMethod() == 'POST');
83 * Prepares the HTML request data for usage by currently copying
84 * $_REQUEST into a private attribute. Later on we can add more
85 * things for initialization here.
89 public function prepareRequestData () {
90 // Copy GET then POST data
91 $this->setRequestData(array_merge($_GET, $_POST));
95 * Getter for a header element or 'null' if header was not found
97 * @param $headerName Name of the header
98 * @return $headerValue Value of the header or 'null' if not found
100 public function getHeaderElement ($headerName) {
101 // Default return value on error
104 // Construct the name
105 $name = 'HTTP_' . strtoupper($this->convertDashesToUnderscores($headerName));
107 // Does this header exist?
108 if (isset($_SERVER[$name])) {
109 $headerValue = $_SERVER[$name];
117 * Getter for request method. This getter might be useful for security filters
119 * @return $requestMethod Used request method
121 public final function getRequestMethod () {
122 return $_SERVER['REQUEST_METHOD'];
126 * Reads a cookie and returns it's value or null if not found
128 * @param $cookieName Name of cookie we shall read
129 * @return $cookieValue Value of cookie or null if not found
131 public final function readCookie ($cookieName) {
132 // Default is no cookie with that name found
135 // Is the cookie set?
136 if (isset($_COOKIE[$cookieName])) {
138 $cookieValue = $_COOKIE[$cookieName];