3 namespace CoreFramework\Request;
5 // Import framework stuff
6 use CoreFramework\Object\BaseFrameworkSystem;
9 * A general request class
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 abstract class BaseRequest extends BaseFrameworkSystem {
32 * Array for the request data
34 private $requestData = array();
37 * Whether this request is valid and can be further processed. The default is
38 * valid so make sure your intercepting filters sets this attribute to false
39 * when they need to intercept the data flow.
41 private $requestIsValid = true;
44 * Protected constructor
46 * @param $className Name of the class
49 protected function __construct ($className) {
50 // Call parent constructor
51 parent::__construct($className);
55 * Checks whether a request element is set
56 * @param $element Name of the request element we want to check
57 * @return $isSet Whether the request element is set
59 public function isRequestElementSet ($element) {
60 // Is this element found?
61 $isSet = isset($this->requestData[$element]);
68 * Getter for request element or 'null' if element was not found
70 * @param $element Name of the request element we want to check
71 * @return $value Value of the found request element or 'null' if the
72 * element was not found
74 public function getRequestElement ($element) {
78 // Is the element set?
79 if ($this->isRequestElementSet($element)) {
81 $value = $this->requestData[$element];
83 // Secure it against attacks
84 $value = htmlentities(strip_tags($value), ENT_QUOTES);
87 // Return the element's value
92 * Setter for request elements
94 * @param $element Request element to se
95 * @param $value Value to set
98 public function setRequestElement ($element, $value) {
99 $this->requestData[$element] = $value;
103 * Setter for request data array
105 * @param $requestData Request element to se
108 public function setRequestData (array $requestData) {
109 $this->requestData = $requestData;
113 * Wrapper method for array_key() function for the request data array
115 * @return $array An array containing all array keys to return
117 public function getParameterNames () {
118 return array_keys($this->requestData);
122 * Sets whether the request was valid (default: true)
124 * @param $isValid Whether the request is valid
127 public final function requestIsValid ($isValid = true) {
128 $this->requestIsValid = (bool) $isValid;
132 * Returns whether this request is valid
134 * @return $requestIsValid Whether this request is valid
136 public final function isRequestValid () {
137 return $this->requestIsValid;