3 namespace Org\Mxchange\CoreFramework\Request;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Request\Requestable;
9 * A concrete and secured HTML request class to make HTML requests more abstract
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 <<<<<<< HEAD:framework/main/classes/request/html/class_HtmlRequest.php
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
16 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
17 >>>>>>> Some updates::inc/main/classes/request/html/class_HtmlRequest.php
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
20 * @todo Move out the cookie part to a seperate class, e.g. Cookie
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class HtmlRequest extends BaseRequest implements Requestable {
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
47 * Creates an instance of this class and prepares it a little
49 * @return $requestInstance An instance of this class
51 public static final function createHtmlRequest () {
53 $requestInstance = new HtmlRequest();
55 // Prepare the HTML request data for usage
56 $requestInstance->prepareRequestData();
58 // Return the prepared instance
59 return $requestInstance;
63 * Checks if the request method is GET.
65 * @return $isGet Whether the request method is GET
67 public function isGetRequestMethod () {
69 return ($this->getRequestMethod() == 'GET');
73 * Checks if the request method is HEAD.
75 * @return $isHead Whether the request method is HEAD
77 public function isHeadRequestMethod () {
79 return ($this->getRequestMethod() == 'HEAD');
83 * Checks if the request method is POST.
85 * @return $isPost Whether the request method is POST
87 public function isPostRequestMethod () {
89 return ($this->getRequestMethod() == 'POST');
93 * Prepares the HTML request data for usage by currently copying
94 * $_REQUEST into a private attribute. Later on we can add more
95 * things for initialization here.
99 protected function prepareRequestData () {
100 // Copy GET then POST data
101 $this->setRequestData(array_merge($_GET, $_POST));
105 * Getter for a header element or 'null' if header was not found
107 * @param $headerName Name of the header
108 * @return $headerValue Value of the header or 'null' if not found
110 public function getHeaderElement ($headerName) {
111 // Default return value on error
114 // Construct the name
115 $name = 'HTTP_' . strtoupper(self::convertDashesToUnderscores($headerName));
117 // Does this header exist?
118 if (isset($_SERVER[$name])) {
119 $headerValue = $_SERVER[$name];
127 * Getter for request method. This getter might be useful for security filters
129 * @return $requestMethod Used request method
131 public final function getRequestMethod () {
132 return $_SERVER['REQUEST_METHOD'];
136 * Reads a cookie and returns it's value or null if not found
138 * @param $cookieName Name of cookie we shall read
139 * @return $cookieValue Value of cookie or null if not found
141 public final function readCookie ($cookieName) {
142 // Default is no cookie with that name found
145 // Is the cookie set?
146 if (isset($_COOKIE[$cookieName])) {
148 $cookieValue = $_COOKIE[$cookieName];