@@ -35,10 +35,9 @@ trait RequestTrait
3535 protected $ ipAddress = '' ;
3636
3737 /**
38- * Stores values we've retrieved from
39- * PHP globals.
38+ * Stores values we've retrieved from PHP globals.
4039 *
41- * @var array
40+ * @var array{get?: array, post?: array, request?: array, cookie?: array, server?: array}
4241 */
4342 protected $ globals = [];
4443
@@ -213,13 +212,15 @@ public function getEnv($index = null, $filter = null, $flags = null)
213212 /**
214213 * Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
215214 *
215+ * @param string $name Supergrlobal name (lowercase)
216+ * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
216217 * @param mixed $value
217218 *
218219 * @return $this
219220 */
220- public function setGlobal (string $ method , $ value )
221+ public function setGlobal (string $ name , $ value )
221222 {
222- $ this ->globals [$ method ] = $ value ;
223+ $ this ->globals [$ name ] = $ value ;
223224
224225 return $ this ;
225226 }
@@ -234,19 +235,18 @@ public function setGlobal(string $method, $value)
234235 *
235236 * http://php.net/manual/en/filter.filters.sanitize.php
236237 *
237- * @param string $method Input filter constant
238+ * @param string $name Supergrlobal name (lowercase)
239+ * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
238240 * @param array|string|null $index
239241 * @param int|null $filter Filter constant
240242 * @param array|int|null $flags Options
241243 *
242244 * @return array|bool|float|int|object|string|null
243245 */
244- public function fetchGlobal (string $ method , $ index = null , ?int $ filter = null , $ flags = null )
246+ public function fetchGlobal (string $ name , $ index = null , ?int $ filter = null , $ flags = null )
245247 {
246- $ method = strtolower ($ method );
247-
248- if (! isset ($ this ->globals [$ method ])) {
249- $ this ->populateGlobals ($ method );
248+ if (! isset ($ this ->globals [$ name ])) {
249+ $ this ->populateGlobals ($ name );
250250 }
251251
252252 // Null filters cause null values to return.
@@ -257,9 +257,9 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
257257 if ($ index === null ) {
258258 $ values = [];
259259
260- foreach ($ this ->globals [$ method ] as $ key => $ value ) {
260+ foreach ($ this ->globals [$ name ] as $ key => $ value ) {
261261 $ values [$ key ] = is_array ($ value )
262- ? $ this ->fetchGlobal ($ method , $ key , $ filter , $ flags )
262+ ? $ this ->fetchGlobal ($ name , $ key , $ filter , $ flags )
263263 : filter_var ($ value , $ filter , $ flags );
264264 }
265265
@@ -271,15 +271,15 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
271271 $ output = [];
272272
273273 foreach ($ index as $ key ) {
274- $ output [$ key ] = $ this ->fetchGlobal ($ method , $ key , $ filter , $ flags );
274+ $ output [$ key ] = $ this ->fetchGlobal ($ name , $ key , $ filter , $ flags );
275275 }
276276
277277 return $ output ;
278278 }
279279
280280 // Does the index contain array notation?
281281 if (($ count = preg_match_all ('/(?:^[^\[]+)|\[[^]]*\]/ ' , $ index , $ matches )) > 1 ) {
282- $ value = $ this ->globals [$ method ];
282+ $ value = $ this ->globals [$ name ];
283283
284284 for ($ i = 0 ; $ i < $ count ; $ i ++) {
285285 $ key = trim ($ matches [0 ][$ i ], '[] ' );
@@ -297,7 +297,7 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
297297 }
298298
299299 if (! isset ($ value )) {
300- $ value = $ this ->globals [$ method ][$ index ] ?? null ;
300+ $ value = $ this ->globals [$ name ][$ index ] ?? null ;
301301 }
302302
303303 if (is_array ($ value )
@@ -326,20 +326,23 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
326326 }
327327
328328 /**
329- * Saves a copy of the current state of one of several PHP globals
329+ * Saves a copy of the current state of one of several PHP globals,
330330 * so we can retrieve them later.
331331 *
332+ * @param string $name Supergrlobal name (lowercase)
333+ * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
334+ *
332335 * @return void
333336 */
334- protected function populateGlobals (string $ method )
337+ protected function populateGlobals (string $ name )
335338 {
336- if (! isset ($ this ->globals [$ method ])) {
337- $ this ->globals [$ method ] = [];
339+ if (! isset ($ this ->globals [$ name ])) {
340+ $ this ->globals [$ name ] = [];
338341 }
339342
340343 // Don't populate ENV as it might contain
341344 // sensitive data that we don't want to get logged.
342- switch ($ method ) {
345+ switch ($ name ) {
343346 case 'get ' :
344347 $ this ->globals ['get ' ] = $ _GET ;
345348 break ;
0 commit comments