Fixed a typo
[core.git] / inc / classes / main / request / class_BaseRequest.php
1 <?php
2 /**
3  * A general request class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
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.
15  *
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.
20  *
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/>.
23  */
24 class BaseRequest extends BaseFrameworkSystem {
25         /**
26          * Array for the request data
27          */
28         private $requestData = array();
29
30         /**
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.
34          */
35         private $requestIsValid = true;
36
37         /**
38          * Protected constructor
39          *
40          * @param       $className      Name of the class
41          * @return      void
42          */
43         protected function __construct ($className) {
44                 // Call parent constructor
45                 parent::__construct($className);
46         }
47
48         /**
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
52          */
53         public function isRequestElementSet ($element) {
54                 // Is this element found?
55                 $isSet = isset($this->requestData[$element]);
56
57                 // Return result
58                 return $isSet;
59         }
60
61         /**
62          * Getter for request element or 'null' if element was not found
63          *
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
67          */
68         public function getRequestElement ($element) {
69                 // Initialize value
70                 $value = NULL;
71
72                 // Is the element set?
73                 if ($this->isRequestElementSet($element)) {
74                         // Get the bare value
75                         $value = $this->requestData[$element];
76
77                         // Secure it against attacks
78                         $value = htmlentities(strip_tags($value), ENT_QUOTES);
79                 } // END - if
80
81                 // Return the element's value
82                 return $value;
83         }
84
85         /**
86          * Setter for request elements
87          *
88          * @param       $element        Request element to se
89          * @param       $value          Value to set
90          * @return      void
91          */
92         public function setRequestElement ($element, $value) {
93                 $this->requestData[$element] = $value;
94         }
95
96         /**
97          * Setter for request data array
98          *
99          * @param       $requestData    Request element to se
100          * @return      void
101          */
102         public function setRequestData (array $requestData) {
103                 $this->requestData = $requestData;
104         }
105
106         /**
107          * Wrapper method for array_key() function for the request data array
108          *
109          * @return      $array  An array containing all array keys to return
110          */
111         public function getParameterNames () {
112                 return array_keys($this->requestData);
113         }
114
115         /**
116          * Sets whether the request was valid (default: true)
117          *
118          * @param       $isValid        Whether the request is valid
119          * @return      void
120          */
121         public final function requestIsValid ($isValid = true) {
122                 $this->requestIsValid = (bool) $isValid;
123         }
124
125         /**
126          * Returns whether this request is valid
127          *
128          * @return      $requestIsValid         Whether this request is valid
129          */
130         public final function isRequestValid () {
131                 return $this->requestIsValid;
132         }
133 }
134
135 // [EOF]
136 ?>