3 namespace Org\Mxchange\CoreFramework\Request;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Request\Requestable;
7 use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
10 * A concrete and secured HTML request class to make HTML requests more abstract
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.shipsimu.org
17 * @todo Move out the cookie part to a seperate class, e.g. Cookie
19 * This program is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 class HtmlRequest extends BaseRequest implements Requestable {
34 * Protected constructor
38 protected function __construct () {
39 // Call parent constructor
40 parent::__construct(__CLASS__);
44 * Creates an instance of this class and prepares it a little
46 * @return $requestInstance An instance of this class
48 public static final function createHtmlRequest () {
50 $requestInstance = new HtmlRequest();
52 // Prepare the HTML request data for usage
53 $requestInstance->prepareRequestData();
55 // Return the prepared instance
56 return $requestInstance;
60 * Checks if the request method is GET.
62 * @return $isGet Whether the request method is GET
64 public function isGetRequestMethod () {
66 return ($this->getRequestMethod() == 'GET');
70 * Checks if the request method is HEAD.
72 * @return $isHead Whether the request method is HEAD
74 public function isHeadRequestMethod () {
76 return ($this->getRequestMethod() == 'HEAD');
80 * Checks if the request method is POST.
82 * @return $isPost Whether the request method is POST
84 public function isPostRequestMethod () {
86 return ($this->getRequestMethod() == 'POST');
90 * Prepares the HTML request data for usage by currently copying
91 * $_REQUEST into a private attribute. Later on we can add more
92 * things for initialization here.
96 protected function prepareRequestData () {
97 // Copy GET then POST data
98 $this->setRequestData(array_merge($_GET, $_POST));
102 * Getter for a header element or 'null' if header was not found
104 * @param $headerName Name of the header
105 * @return $headerValue Value of the header or 'null' if not found
107 public function getHeaderElement ($headerName) {
108 // Default return value on error
111 // Construct the name
112 $name = 'HTTP_' . strtoupper(StringUtils::convertDashesToUnderscores($headerName));
114 // Does this header exist?
115 if (isset($_SERVER[$name])) {
116 $headerValue = $_SERVER[$name];
124 * Getter for request method. This getter might be useful for security filters
126 * @return $requestMethod Used request method
128 public final function getRequestMethod () {
129 return $_SERVER['REQUEST_METHOD'];
133 * Reads a cookie and returns it's value or null if not found
135 * @param $cookieName Name of cookie we shall read
136 * @return $cookieValue Value of cookie or null if not found
138 public final function readCookie ($cookieName) {
139 // Default is no cookie with that name found
142 // Is the cookie set?
143 if (isset($_COOKIE[$cookieName])) {
145 $cookieValue = $_COOKIE[$cookieName];