Skip to content

Commit af2803c

Browse files
authored
Merge pull request #32 from WebFiori/dev
Fix fo IIS issue on DOC_ROOT + Added Support for Getting All GET or POST Parameters
2 parents f2c263e + 6e11815 commit af2803c

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

webfiori/http/Request.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,21 +284,37 @@ public static function getMethod() : string {
284284
* @since 1.0.1
285285
*/
286286
public static function getParam(string $paramName) {
287-
$requMethod = self::getMethod();
287+
288288
$trimmed = trim($paramName);
289-
$val = null;
289+
$params = self::getParams();
290290

291-
if ($requMethod == 'POST' || $requMethod == 'PUT') {
292-
$val = self::filter(INPUT_POST, $trimmed);
293-
} else if ($requMethod == 'DELETE' || $requMethod == 'GET') {
294-
$val = self::filter(INPUT_GET, $trimmed);
291+
if (isset($params[$trimmed])) {
292+
return $params[$trimmed];
295293
}
296294

297-
if ($val === false) {
298-
return null;
295+
return null;
296+
}
297+
/**
298+
* Returns an array that contains all POST or GET parameters.
299+
*
300+
* @return array An array that contains all POST or GET parameters. The
301+
* indices of the array are parameters names and the value of each index
302+
* is the value of the parameter.
303+
*/
304+
public static function getParams() : array {
305+
$requMethod = self::getMethod();
306+
$retVal = [];
307+
308+
if ($requMethod == 'POST' || $requMethod == 'PUT') {
309+
foreach (array_keys($_POST) as $name) {
310+
$retVal[$name] = self::filter(INPUT_POST, $name);
311+
}
312+
} else if ($requMethod == 'DELETE' || $requMethod == 'GET') {
313+
foreach (array_keys($_GET) as $name) {
314+
$retVal[$name] = self::filter(INPUT_GET, $name);
315+
}
299316
}
300-
301-
return $val;
317+
return $retVal;
302318
}
303319
/**
304320
* Returns the URI of the requested resource.

webfiori/http/Uri.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,15 @@ public static function getBaseURL() : string {
203203
if (strlen($secureHost) != 0 && !$useHttp) {
204204
$protocol = "https://";
205205
}
206-
$docRoot = filter_var($_SERVER['DOCUMENT_ROOT']);
206+
207+
if (isset($_SERVER['DOCUMENT_ROOT'])) {
208+
$docRoot = filter_var($_SERVER['DOCUMENT_ROOT']);
209+
} else {
210+
//Fix for IIS since the $_SERVER['DOCUMENT_ROOT'] is not set
211+
//in some cases
212+
$docRoot = getcwd();
213+
}
214+
207215
$docRootLen = strlen($docRoot);
208216

209217
if ($docRootLen == 0) {

0 commit comments

Comments
 (0)