Skip to content

Commit 72a6fb8

Browse files
committed
Update Request.php
1 parent 6b4f6e7 commit 72a6fb8

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/Request.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* request. Note that it does not comply with PSR-7 in all aspects.
3131
* @author Ibrahim
3232
*
33-
* @version 1.0
33+
* @version 1.0.1
3434
*/
3535
class Request {
3636
/**
@@ -90,6 +90,35 @@ private function __construct() {
9090
$this->requestedUri = null;
9191
$this->requestHeaders = null;
9292
}
93+
/**
94+
* Returns the value of a GET or POST parameter.
95+
*
96+
* This method will apply basic filtering to the value of the parameter before returning
97+
* it.
98+
*
99+
* @param string $paramName The name of the parameter. Note that if the value has extra
100+
* spaces, they will be trimmed.
101+
*
102+
* @return string|null The method will return the value of the parameter if
103+
* set. Other than that, the method will return null.
104+
*
105+
* @since 1.0.1
106+
*/
107+
public static function getParam($paramName) {
108+
$requMethod = self::getMethod();
109+
$trimmed = trim($paramName);
110+
$val = null;
111+
112+
if ($requMethod == 'POST' || $requMethod == 'PUT') {
113+
$val = filter_input(INPUT_POST, $trimmed);
114+
} else if ($requMethod == 'DELETE' || $requMethod == 'GET') {
115+
$val = filter_input(INPUT_GET, $trimmed);
116+
}
117+
118+
if ($val === false) {
119+
return null;
120+
}
121+
}
93122
/**
94123
* Returns the IP address of the user who is connected to the server.
95124
*

0 commit comments

Comments
 (0)