@@ -28,6 +28,7 @@ class Input implements InputInterface
2828 protected $ input ;
2929 /** @var object khởi tạo đối tượng đến class \nguyenanhung\MyRequests\Ip */
3030 protected $ ip ;
31+
3132 /**
3233 * Raw input stream data
3334 *
@@ -36,6 +37,7 @@ class Input implements InputInterface
3637 * @var string
3738 */
3839 protected $ rawInputStream ;
40+
3941 /**
4042 * Parsed input stream data
4143 *
@@ -44,6 +46,7 @@ class Input implements InputInterface
4446 * @var array
4547 */
4648 protected $ inputStream ;
49+
4750 /**
4851 * Enable XSS flag
4952 *
@@ -54,6 +57,7 @@ class Input implements InputInterface
5457 * @var bool
5558 */
5659 protected $ enableXss = FALSE ;
60+
5761 /**
5862 * List of all HTTP request headers
5963 *
@@ -63,6 +67,9 @@ class Input implements InputInterface
6367
6468 /**
6569 * Input constructor.
70+ *
71+ * @author : 713uk13m <[email protected] > 72+ * @copyright: 713uk13m <[email protected] > 6673 */
6774 public function __construct ()
6875 {
@@ -73,10 +80,10 @@ public function __construct()
7380 /**
7481 * Function rawInputStream
7582 *
76- * @return $this
77- * @author: 713uk13m <[email protected] > 78- * @time : 2018-12-26 14:25
79- *
83+ * @return $this|\nguyenanhung\MyRequests\Input
84+ * @author : 713uk13m <[email protected] > 85+ * @copyright: 713uk13m <[email protected] > 86+ * @time : 03/18/2021 59:59
8087 */
8188 public function rawInputStream ()
8289 {
@@ -89,10 +96,10 @@ public function rawInputStream()
8996 /**
9097 * Function getRawInputStream
9198 *
92- * @return mixed
93- * @author: 713uk13m <[email protected] > 94- * @time : 2018-12-26 14:25
95- *
99+ * @return mixed|string
100+ * @author : 713uk13m <[email protected] > 101+ * @copyright: 713uk13m <[email protected] > 102+ * @time : 03/18/2021 00:12
96103 */
97104 public function getRawInputStream ()
98105 {
@@ -105,10 +112,10 @@ public function getRawInputStream()
105112 * @param null $index
106113 * @param null $xss_clean
107114 *
108- * @return mixed
109- * @author: 713uk13m <[email protected] > 110- * @time : 2018-12-26 14:32
111- *
115+ * @return array| mixed|null
116+ * @author : 713uk13m <[email protected] > 117+ * @copyright: 713uk13m <[email protected] > 118+ * @time : 03/18/2021 00:18
112119 */
113120 public function inputStream ($ index = NULL , $ xss_clean = NULL )
114121 {
@@ -124,14 +131,14 @@ public function inputStream($index = NULL, $xss_clean = NULL)
124131 }
125132
126133 /**
127- * Hàm lấy thông tin Request Method
134+ * Function method - Hàm lấy thông tin Request Method
128135 *
129- * Return the request method
136+ * @param false $upper Whether to return in upper or lower case (default: FALSE)
130137 *
131- * @param bool $upper Whether to return in upper or lower case
132- * (default: FALSE)
133- *
134- * @return string
138+ * @return string
139+ * @author : 713uk13m <[email protected] > 140+ * @copyright: 713uk13m <[email protected] > 141+ * @time : 03/18/2021 00:27
135142 */
136143 public function method ($ upper = FALSE )
137144 {
@@ -143,13 +150,13 @@ public function method($upper = FALSE)
143150 /**
144151 * Hàm lấy dữ liệu từ $_POST
145152 *
146- * @param string $key POST parameter name
147- * @param bool $xss_clean Whether to apply XSS filtering
153+ * @param string|mixed $key POST parameter name
154+ * @param bool $xss_clean Whether to apply XSS filtering
148155 *
149- * @return mixed|null| string|string[] $_POST if no parameters supplied, otherwise the POST value if found or NULL
150- * if not
151- * @author : 713uk13m <[email protected] > 152- * @time : 10/18/18 10:58
156+ * @return bool|float|int|mixed| string|string[]|null $_POST if no parameters supplied, otherwise the POST value if found or NULL if not
157+ * @author : 713uk13m <[email protected] > 158+ * @copyright : 713uk13m <[email protected] > 159+ * @time : 10/18/18 10:58
153160 *
154161 */
155162 public function post ($ key = '' , $ xss_clean = FALSE )
@@ -169,13 +176,13 @@ public function post($key = '', $xss_clean = FALSE)
169176 /**
170177 * Hàm lấy dữ liệu từ $_GET
171178 *
172- * @param string $key GET parameter name
173- * @param bool $xss_clean Whether to apply XSS filtering
179+ * @param string|mixed $key GET parameter name
180+ * @param bool $xss_clean Whether to apply XSS filtering
174181 *
175- * @return mixed|null|string|string[] $_GET if no parameters supplied, otherwise the GET value if found or NULL
176- * if not
177- * @author : 713uk13m <[email protected] > 178- * @time : 10/18/18 10:58
182+ * @return mixed|null|string|string[] $_GET if no parameters supplied, otherwise the GET value if found or NULL if not
183+ * @author : 713uk13m <[email protected] > 184+ * @copyright : 713uk13m <[email protected] > 185+ * @time : 10/18/18 10:58
179186 *
180187 */
181188 public function get ($ key = '' , $ xss_clean = FALSE )
@@ -195,13 +202,13 @@ public function get($key = '', $xss_clean = FALSE)
195202 /**
196203 * Hàm lấy dữ liệu từ $_SERVER
197204 *
198- * @param string $key SERVER parameter name
199- * @param bool $xss_clean Whether to apply XSS filtering
205+ * @param string|mixed $key SERVER parameter name
206+ * @param bool $xss_clean Whether to apply XSS filtering
200207 *
201- * @return mixed|null|string|string[] $_SERVER f no parameters supplied, otherwise the SERVER value if found or NULL
202- * if not
203- * @author : 713uk13m <[email protected] > 204- * @time : 10/18/18 10:58
208+ * @return mixed|null|string|string[] $_SERVER f no parameters supplied, otherwise the SERVER value if found or NULL if not
209+ * @author : 713uk13m <[email protected] > 210+ * @copyright : 713uk13m <[email protected] > 211+ * @time : 10/18/18 10:58
205212 *
206213 */
207214 public function server ($ key = '' , $ xss_clean = FALSE )
@@ -221,13 +228,13 @@ public function server($key = '', $xss_clean = FALSE)
221228 /**
222229 * Hàm lấy dữ liệu từ $_COOKIE
223230 *
224- * @param string $key COOKIE parameter name
225- * @param bool $xss_clean Whether to apply XSS filtering
231+ * @param string|mixed $key COOKIE parameter name
232+ * @param bool $xss_clean Whether to apply XSS filtering
226233 *
227- * @return mixed|null|string|string[] $_COOKIE f no parameters supplied, otherwise the COOKIE value if found or NULL
228- * if not
229- * @author : 713uk13m <[email protected] > 230- * @time : 10/18/18 10:58
234+ * @return mixed|null|string|string[] $_COOKIE f no parameters supplied, otherwise the COOKIE value if found or NULL if not
235+ * @author : 713uk13m <[email protected] > 236+ * @copyright : 713uk13m <[email protected] > 237+ * @time : 10/18/18 10:58
231238 *
232239 */
233240 public function cookie ($ key = '' , $ xss_clean = FALSE )
@@ -247,13 +254,13 @@ public function cookie($key = '', $xss_clean = FALSE)
247254 /**
248255 * Hàm lấy dữ liệu từ $_FILES
249256 *
250- * @param string $key FILES parameter name
251- * @param bool $xss_clean Whether to apply XSS filtering
257+ * @param string|mixed $key FILES parameter name
258+ * @param bool $xss_clean Whether to apply XSS filtering
252259 *
253- * @return mixed|null|string|string[] $_FILES f no parameters supplied, otherwise the FILES value if found or NULL
254- * if not
255- * @author : 713uk13m <[email protected] > 256- * @time : 10/18/18 10:58
260+ * @return mixed|null|string|string[] $_FILES f no parameters supplied, otherwise the FILES value if found or NULL if not
261+ * @author : 713uk13m <[email protected] > 262+ * @copyright : 713uk13m <[email protected] > 263+ * @time : 10/18/18 10:58
257264 *
258265 */
259266 public function file ($ key = '' , $ xss_clean = FALSE )
@@ -273,13 +280,13 @@ public function file($key = '', $xss_clean = FALSE)
273280 /**
274281 * Hàm lấy dữ liệu từ $_SERVER Header
275282 *
276- * @param string $key _SERVER parameter name
277- * @param bool $xss_clean Whether to apply XSS filtering
283+ * @param string|mixed $key _SERVER parameter name
284+ * @param bool $xss_clean Whether to apply XSS filtering
278285 *
279- * @return mixed|null|string|string[] $_SERVER f no parameters supplied, otherwise the _SERVER value if found or
280- * NULL if not
281- * @author : 713uk13m <[email protected] > 282- * @time : 10/18/18 10:58
286+ * @return mixed|null|string|string[] $_SERVER f no parameters supplied, otherwise the _SERVER value if found or NULL if not
287+ * @author : 713uk13m <[email protected] > 288+ * @copyright : 713uk13m <[email protected] > 289+ * @time : 10/18/18 10:58
283290 *
284291 */
285292 public function header ($ key = '' , $ xss_clean = FALSE )
@@ -300,17 +307,16 @@ public function header($key = '', $xss_clean = FALSE)
300307 * Hàm lấy địa chỉ IP của người dùng
301308 *
302309 * @return bool|int|mixed|string
303- * @author: 713uk13m <[email protected] > 304- * @time : 10/18/18 11:41
310+ * @author : 713uk13m <[email protected] > 311+ * @copyright : 713uk13m <[email protected] > 312+ * @time : 10/18/18 11:41
305313 *
306314 */
307315 public function ip_address ()
308316 {
309317 return $ this ->ip ->getIpAddress ();
310318 }
311319
312- // -------------------------------------------------------------------- //
313-
314320 /**
315321 * Request Headers
316322 *
@@ -324,6 +330,7 @@ public function requestHeaders($xss_clean = FALSE)
324330 if (!empty ($ this ->headers )) {
325331 return $ this ->fetchFromArray ($ this ->headers , NULL , $ xss_clean );
326332 }
333+
327334 // In Apache, you can simply call apache_request_headers()
328335 if (function_exists ('apache_request_headers ' )) {
329336 $ this ->headers = apache_request_headers ();
@@ -395,8 +402,6 @@ public function isCLI()
395402 return (PHP_SAPI === 'cli ' or defined ('STDIN ' ));
396403 }
397404
398- // -------------------------------------------------------------------- //
399-
400405 /**
401406 * Fetch from Array
402407 *
@@ -413,8 +418,10 @@ public function isCLI()
413418 public function fetchFromArray (&$ array , $ index = NULL , $ xss_clean = NULL )
414419 {
415420 is_bool ($ xss_clean ) or $ xss_clean = $ this ->enableXss ;
421+
416422 // If $index is NULL, it means that the whole $array is requested
417423 isset ($ index ) or $ index = array_keys ($ array );
424+
418425 // allow fetching multiple keys at once
419426 if (is_array ($ index )) {
420427 $ output = array ();
@@ -424,10 +431,10 @@ public function fetchFromArray(&$array, $index = NULL, $xss_clean = NULL)
424431
425432 return $ output ;
426433 }
434+ $ patternArray = '/(?:^[^\[]+)|\[[^]]*\]/ ' ; // Does the index contain array notation
427435 if (isset ($ array [$ index ])) {
428436 $ value = $ array [$ index ];
429- } elseif (($ count = preg_match_all ('/(?:^[^\[]+)|\[[^]]*\]/ ' , $ index , $ matches )) > 1 ) // Does the index contain array notation
430- {
437+ } elseif (($ count = preg_match_all ($ patternArray , $ index , $ matches )) > 1 ) {
431438 $ value = $ array ;
432439 for ($ i = 0 ; $ i < $ count ; $ i ++) {
433440 $ key = trim ($ matches [0 ][$ i ], '[] ' );
0 commit comments