]> git.mxchange.org Git - core.git/blob - framework/main/classes/request/class_BaseRequest.php
Some updates:
[core.git] / framework / main / classes / request / class_BaseRequest.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Request;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
7
8 /**
9  * A general request class
10  *
11  * @author              Roland Haeder <webmaster@shipsimu.org>
12  * @version             0.0.0
13 <<<<<<< HEAD:framework/main/classes/request/class_BaseRequest.php
14  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15 =======
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
20  *
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.
25  *
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.
30  *
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/>.
33  */
34 abstract class BaseRequest extends BaseFrameworkSystem {
35         /**
36          * Array for the request data
37          */
38         private $requestData = array();
39
40         /**
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.
44          */
45         private $requestIsValid = true;
46
47         /**
48          * Protected constructor
49          *
50          * @param       $className      Name of the class
51          * @return      void
52          */
53         protected function __construct ($className) {
54                 // Call parent constructor
55                 parent::__construct($className);
56         }
57
58         /**
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
62          */
63         public function isRequestElementSet ($element) {
64                 // Is this element found?
65                 $isSet = isset($this->requestData[$element]);
66
67                 // Return result
68                 return $isSet;
69         }
70
71         /**
72          * Getter for request element or 'null' if element was not found
73          *
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
77          */
78         public function getRequestElement ($element) {
79                 // Initialize value
80                 $value = NULL;
81
82                 // Is the element set?
83                 if ($this->isRequestElementSet($element)) {
84                         // Get the bare value
85                         $value = $this->requestData[$element];
86
87                         // Secure it against attacks
88                         $value = htmlentities(strip_tags($value), ENT_QUOTES);
89                 } // END - if
90
91                 // Return the element's value
92                 return $value;
93         }
94
95         /**
96          * Setter for request elements
97          *
98          * @param       $element        Request element to se
99          * @param       $value          Value to set
100          * @return      void
101          */
102         public function setRequestElement ($element, $value) {
103                 $this->requestData[$element] = $value;
104         }
105
106         /**
107          * Setter for request data array
108          *
109          * @param       $requestData    Request element to se
110          * @return      void
111          */
112         public function setRequestData (array $requestData) {
113                 $this->requestData = $requestData;
114         }
115
116         /**
117          * Wrapper method for array_key() function for the request data array
118          *
119          * @return      $array  An array containing all array keys to return
120          */
121         public function getParameterNames () {
122                 return array_keys($this->requestData);
123         }
124
125         /**
126          * Sets whether the request was valid (default: true)
127          *
128          * @param       $isValid        Whether the request is valid
129          * @return      void
130          */
131         public final function requestIsValid ($isValid = true) {
132                 $this->requestIsValid = (bool) $isValid;
133         }
134
135         /**
136          * Returns whether this request is valid
137          *
138          * @return      $requestIsValid         Whether this request is valid
139          */
140         public final function isRequestValid () {
141                 return $this->requestIsValid;
142         }
143
144 }