1 | <?php |
||
43 | class Request extends Mother |
||
44 | { |
||
45 | /** |
||
46 | * Query constructor. |
||
47 | */ |
||
48 | public function __construct() |
||
57 | |||
58 | /** |
||
59 | * if the request is ajax |
||
60 | * |
||
61 | * @access public |
||
62 | * @param string $sName name of the template |
||
|
|||
63 | * @return bool |
||
64 | */ |
||
65 | public static function isXmlHttpRequest() |
||
66 | { |
||
67 | if (!self::isCliRequest()) { |
||
68 | |||
69 | if (array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { |
||
70 | |||
71 | return true; |
||
72 | } |
||
73 | else { |
||
74 | |||
75 | return false; |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * if the request is http (web site or web service) |
||
82 | * |
||
83 | * @access public |
||
84 | * @return bool |
||
85 | */ |
||
86 | public static function isHttpRequest() |
||
87 | { |
||
88 | if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) { return true; } |
||
89 | else { return false; } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * if the request is https (web site or web service) |
||
94 | * |
||
95 | * @access public |
||
96 | * @return bool |
||
97 | */ |
||
98 | public static function isHttpsRequest() |
||
99 | { |
||
100 | if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') { return true; } |
||
101 | else { return false; } |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * if the request is http (web site or web service) |
||
106 | * |
||
107 | * @access public |
||
108 | * @return bool |
||
109 | */ |
||
110 | public static function isCliRequest() |
||
111 | { |
||
112 | $sSapiType = php_sapi_name(); |
||
113 | |||
114 | if (substr($sSapiType, 0, 3) == 'cgi' || defined('STDIN')) { return true; } |
||
115 | else { return false; } |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * if the request is http (web site or web service) |
||
120 | * |
||
121 | * @access public |
||
122 | * @return bool |
||
123 | * @deprecated don't use this method because they return a false result |
||
124 | * delete in the version 5 |
||
125 | * @throws \Exception |
||
126 | */ |
||
127 | public static function getPreferredLanguage() |
||
128 | { |
||
129 | throw new \Exception("Use getLanguages() method now!"); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * if the request is http (web site or web service) |
||
134 | * |
||
135 | * @access public |
||
136 | * @return bool |
||
137 | */ |
||
138 | public static function getParameters() |
||
139 | { |
||
140 | if (isset($_GET)) { return $_GET; } |
||
141 | else { return array(); } |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * if the request is http (web site or web service) |
||
146 | * |
||
147 | * @access public |
||
148 | * @return bool |
||
149 | */ |
||
150 | public static function getPostParameters() |
||
151 | { |
||
152 | if (isset($_POST)) { return $_POST; } |
||
153 | else { return array(); } |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * if there are POST parameters |
||
158 | * |
||
159 | * @access public |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function isPost() |
||
163 | { |
||
164 | if (isset($_POST) && count($_POST) > 0) { return true; } |
||
165 | else { return false; } |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * get the POST for $sName |
||
170 | * |
||
171 | * @access public |
||
172 | * @param string $name |
||
173 | * @return mixed |
||
174 | * @deprecated please use $this->request->get() |
||
175 | * delete in the version 5 |
||
176 | */ |
||
177 | public function getPost(string $name) |
||
178 | { |
||
179 | return $this->request->get($name); |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * get the put method |
||
184 | * |
||
185 | * @access public |
||
186 | * @return array |
||
187 | */ |
||
188 | public static function getPut() |
||
189 | { |
||
190 | $aPut = array(); |
||
191 | |||
192 | $rPutResource = fopen("php://input", "r"); |
||
193 | |||
194 | while ($sData = fread($rPutResource, 1024)) { |
||
195 | |||
196 | $aSeparatePut = explode('&', $sData); |
||
197 | |||
198 | foreach($aSeparatePut as $sOne) { |
||
199 | |||
200 | $aOnePut = explode('=', $sOne); |
||
201 | $aPut[$aOnePut[0]] = $aOnePut[1]; |
||
202 | } |
||
203 | } |
||
204 | |||
205 | return $aPut; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Set the HTTP status |
||
210 | * |
||
211 | * @access public |
||
212 | * @param int $iCode |
||
213 | * @return void |
||
214 | */ |
||
215 | public static function setStatus($iCode) |
||
223 | |||
224 | /** |
||
225 | * get http method |
||
226 | * @return string |
||
227 | */ |
||
228 | public function getMethod() : string |
||
232 | |||
233 | /** |
||
234 | * return languages accepted by the customer |
||
235 | * @return array |
||
236 | */ |
||
237 | public function getLanguages() : array |
||
242 | |||
243 | /** |
||
244 | * get path info |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getPathInfo() : string |
||
251 | } |
||
252 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.