3 * A general request class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.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 * Wether 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);
48 $this->removeNumberFormaters();
49 $this->removeSystemArray();
53 * Checks wether a request element is set
54 * @param $element Name of the request element we want to check
55 * @return $isSet Wether the request element is set
57 public function isRequestElementSet ($element) {
58 // Is this element found?
59 $isSet = isset($this->requestData[$element]);
66 * Getter for request element or 'null' if element was not found
68 * @param $element Name of the request element we want to check
69 * @return $value Value of the found request element or 'null' if the
70 * element was not found
72 public function getRequestElement ($element) {
76 // Is the element set?
77 if ($this->isRequestElementSet($element)) {
79 $value = $this->requestData[$element];
81 // Secure it against attacks
82 $value = htmlentities(strip_tags($value), ENT_QUOTES);
85 // Return the element's value
90 * Setter for request elements
92 * @param $element Request element to se
93 * @param $value Value to set
96 public function setRequestElement ($element, $value) {
97 $this->requestData[$element] = $value;
101 * Setter for request data array
103 * @param $requestData Request element to se
106 public function setRequestData (array $requestData) {
107 $this->requestData = $requestData;
111 * Wrapper method for array_key() function for the request data array
113 * @return $array An array containing all array keys to return
115 public function getParameterNames () {
116 return array_keys($this->requestData);
120 * Sets wether the request was valid (default: true)
122 * @param $isValid Wether the request is valid
125 public final function requestIsValid ($isValid = true) {
126 $this->requestIsValid = (bool) $isValid;
130 * Returns wether this request is valid
132 * @return $requestIsValid Wether this request is valid
134 public final function isRequestValid () {
135 return $this->requestIsValid;