3 namespace Org\Mxchange\CoreFramework\Request;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
9 * A general request class
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 <<<<<<< HEAD:framework/main/classes/request/class_BaseRequest.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/class_BaseRequest.php
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 abstract class BaseRequest extends BaseFrameworkSystem {
36 * Array for the request data
38 private $requestData = array();
41 * Whether this request is valid and can be further processed. The default is
42 * valid so make sure your intercepting filters sets this attribute to false
43 * when they need to intercept the data flow.
45 private $requestIsValid = true;
48 * Protected constructor
50 * @param $className Name of the class
53 protected function __construct ($className) {
54 // Call parent constructor
55 parent::__construct($className);
59 * Checks whether a request element is set
60 * @param $element Name of the request element we want to check
61 * @return $isSet Whether the request element is set
63 public function isRequestElementSet ($element) {
64 // Is this element found?
65 $isSet = isset($this->requestData[$element]);
72 * Getter for request element or 'null' if element was not found
74 * @param $element Name of the request element we want to check
75 * @return $value Value of the found request element or 'null' if the
76 * element was not found
78 public function getRequestElement ($element) {
82 // Is the element set?
83 if ($this->isRequestElementSet($element)) {
85 $value = $this->requestData[$element];
87 // Secure it against attacks
88 $value = htmlentities(strip_tags($value), ENT_QUOTES);
91 // Return the element's value
96 * Setter for request elements
98 * @param $element Request element to se
99 * @param $value Value to set
102 public function setRequestElement ($element, $value) {
103 $this->requestData[$element] = $value;
107 * Setter for request data array
109 * @param $requestData Request element to se
112 public function setRequestData (array $requestData) {
113 $this->requestData = $requestData;
117 * Wrapper method for array_key() function for the request data array
119 * @return $array An array containing all array keys to return
121 public function getParameterNames () {
122 return array_keys($this->requestData);
126 * Sets whether the request was valid (default: true)
128 * @param $isValid Whether the request is valid
131 public final function requestIsValid ($isValid = true) {
132 $this->requestIsValid = (bool) $isValid;
136 * Returns whether this request is valid
138 * @return $requestIsValid Whether this request is valid
140 public final function isRequestValid () {
141 return $this->requestIsValid;