3 namespace CoreFramework\Request;
6 * A concrete and secured HTML request class to make HTML requests more abstract
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
12 * @link http://www.shipsimu.org
13 * @todo Move out the cookie part to a seperate class, e.g. Cookie
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 class HtmlRequest extends BaseRequest implements Requestable {
30 * Protected constructor
34 protected function __construct () {
35 // Call parent constructor
36 parent::__construct(__CLASS__);
40 * Creates an instance of this class and prepares it a little
42 * @return $requestInstance An instance of this class
44 public static final function createHtmlRequest () {
46 $requestInstance = new HtmlRequest();
48 // Prepare the HTML request data for usage
49 $requestInstance->prepareRequestData();
51 // Return the prepared instance
52 return $requestInstance;
56 * Checks if the request method is GET.
58 * @return $isGet Whether the request method is GET
60 public function isGetRequestMethod () {
62 return ($this->getRequestMethod() == 'GET');
66 * Checks if the request method is HEAD.
68 * @return $isHead Whether the request method is HEAD
70 public function isHeadRequestMethod () {
72 return ($this->getRequestMethod() == 'HEAD');
76 * Checks if the request method is POST.
78 * @return $isPost Whether the request method is POST
80 public function isPostRequestMethod () {
82 return ($this->getRequestMethod() == 'POST');
86 * Prepares the HTML request data for usage by currently copying
87 * $_REQUEST into a private attribute. Later on we can add more
88 * things for initialization here.
92 public function prepareRequestData () {
93 // Copy GET then POST data
94 $this->setRequestData(array_merge($_GET, $_POST));
98 * Getter for a header element or 'null' if header was not found
100 * @param $headerName Name of the header
101 * @return $headerValue Value of the header or 'null' if not found
103 public function getHeaderElement ($headerName) {
104 // Default return value on error
107 // Construct the name
108 $name = 'HTTP_' . strtoupper(self::convertDashesToUnderscores($headerName));
110 // Does this header exist?
111 if (isset($_SERVER[$name])) {
112 $headerValue = $_SERVER[$name];
120 * Getter for request method. This getter might be useful for security filters
122 * @return $requestMethod Used request method
124 public final function getRequestMethod () {
125 return $_SERVER['REQUEST_METHOD'];
129 * Reads a cookie and returns it's value or null if not found
131 * @param $cookieName Name of cookie we shall read
132 * @return $cookieValue Value of cookie or null if not found
134 public final function readCookie ($cookieName) {
135 // Default is no cookie with that name found
138 // Is the cookie set?
139 if (isset($_COOKIE[$cookieName])) {
141 $cookieValue = $_COOKIE[$cookieName];