3 * A general request class
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class BaseRequest extends BaseFrameworkSystem {
26 * Array for the request data
28 private $requestData = array();
31 * Whether this request is valid and can be further processed. The default is
32 * valid so make sure your intercepting filters sets this attribute to FALSE
33 * when they need to intercept the data flow.
35 private $requestIsValid = TRUE;
38 * Protected constructor
40 * @param $className Name of the class
43 protected function __construct ($className) {
44 // Call parent constructor
45 parent::__construct($className);
49 * Checks whether a request element is set
50 * @param $element Name of the request element we want to check
51 * @return $isSet Whether the request element is set
53 public function isRequestElementSet ($element) {
54 // Is this element found?
55 $isSet = isset($this->requestData[$element]);
62 * Getter for request element or 'null' if element was not found
64 * @param $element Name of the request element we want to check
65 * @return $value Value of the found request element or 'null' if the
66 * element was not found
68 public function getRequestElement ($element) {
72 // Is the element set?
73 if ($this->isRequestElementSet($element)) {
75 $value = $this->requestData[$element];
77 // Secure it against attacks
78 $value = htmlentities(strip_tags($value), ENT_QUOTES);
81 // Return the element's value
86 * Setter for request elements
88 * @param $element Request element to se
89 * @param $value Value to set
92 public function setRequestElement ($element, $value) {
93 $this->requestData[$element] = $value;
97 * Setter for request data array
99 * @param $requestData Request element to se
102 public function setRequestData (array $requestData) {
103 $this->requestData = $requestData;
107 * Wrapper method for array_key() function for the request data array
109 * @return $array An array containing all array keys to return
111 public function getParameterNames () {
112 return array_keys($this->requestData);
116 * Sets whether the request was valid (default: TRUE)
118 * @param $isValid Whether the request is valid
121 public final function requestIsValid ($isValid = TRUE) {
122 $this->requestIsValid = (bool) $isValid;
126 * Returns whether this request is valid
128 * @return $requestIsValid Whether this request is valid
130 public final function isRequestValid () {
131 return $this->requestIsValid;