@@ -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
@@ -204,22 +203,27 @@ public function getServer($index = null, $filter = null, $flags = null)
204203 * @param array|int|null $flags
205204 *
206205 * @return mixed
206+ *
207+ * @deprecated 4.4.4 This method does not work from the beginning. Use `env()`.
207208 */
208209 public function getEnv ($ index = null , $ filter = null , $ flags = null )
209210 {
211+ // @phpstan-ignore-next-line
210212 return $ this ->fetchGlobal ('env ' , $ index , $ filter , $ flags );
211213 }
212214
213215 /**
214216 * Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
215217 *
218+ * @param string $name Supergrlobal name (lowercase)
219+ * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
216220 * @param mixed $value
217221 *
218222 * @return $this
219223 */
220- public function setGlobal (string $ method , $ value )
224+ public function setGlobal (string $ name , $ value )
221225 {
222- $ this ->globals [$ method ] = $ value ;
226+ $ this ->globals [$ name ] = $ value ;
223227
224228 return $ this ;
225229 }
@@ -234,19 +238,18 @@ public function setGlobal(string $method, $value)
234238 *
235239 * http://php.net/manual/en/filter.filters.sanitize.php
236240 *
237- * @param string $method Input filter constant
241+ * @param string $name Supergrlobal name (lowercase)
242+ * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
238243 * @param array|string|null $index
239244 * @param int|null $filter Filter constant
240245 * @param array|int|null $flags Options
241246 *
242247 * @return array|bool|float|int|object|string|null
243248 */
244- public function fetchGlobal (string $ method , $ index = null , ?int $ filter = null , $ flags = null )
249+ public function fetchGlobal (string $ name , $ index = null , ?int $ filter = null , $ flags = null )
245250 {
246- $ method = strtolower ($ method );
247-
248- if (! isset ($ this ->globals [$ method ])) {
249- $ this ->populateGlobals ($ method );
251+ if (! isset ($ this ->globals [$ name ])) {
252+ $ this ->populateGlobals ($ name );
250253 }
251254
252255 // Null filters cause null values to return.
@@ -257,9 +260,9 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
257260 if ($ index === null ) {
258261 $ values = [];
259262
260- foreach ($ this ->globals [$ method ] as $ key => $ value ) {
263+ foreach ($ this ->globals [$ name ] as $ key => $ value ) {
261264 $ values [$ key ] = is_array ($ value )
262- ? $ this ->fetchGlobal ($ method , $ key , $ filter , $ flags )
265+ ? $ this ->fetchGlobal ($ name , $ key , $ filter , $ flags )
263266 : filter_var ($ value , $ filter , $ flags );
264267 }
265268
@@ -271,15 +274,15 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
271274 $ output = [];
272275
273276 foreach ($ index as $ key ) {
274- $ output [$ key ] = $ this ->fetchGlobal ($ method , $ key , $ filter , $ flags );
277+ $ output [$ key ] = $ this ->fetchGlobal ($ name , $ key , $ filter , $ flags );
275278 }
276279
277280 return $ output ;
278281 }
279282
280283 // Does the index contain array notation?
281284 if (($ count = preg_match_all ('/(?:^[^\[]+)|\[[^]]*\]/ ' , $ index , $ matches )) > 1 ) {
282- $ value = $ this ->globals [$ method ];
285+ $ value = $ this ->globals [$ name ];
283286
284287 for ($ i = 0 ; $ i < $ count ; $ i ++) {
285288 $ key = trim ($ matches [0 ][$ i ], '[] ' );
@@ -297,7 +300,7 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
297300 }
298301
299302 if (! isset ($ value )) {
300- $ value = $ this ->globals [$ method ][$ index ] ?? null ;
303+ $ value = $ this ->globals [$ name ][$ index ] ?? null ;
301304 }
302305
303306 if (is_array ($ value )
@@ -326,20 +329,23 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
326329 }
327330
328331 /**
329- * Saves a copy of the current state of one of several PHP globals
332+ * Saves a copy of the current state of one of several PHP globals,
330333 * so we can retrieve them later.
331334 *
335+ * @param string $name Superglobal name (lowercase)
336+ * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
337+ *
332338 * @return void
333339 */
334- protected function populateGlobals (string $ method )
340+ protected function populateGlobals (string $ name )
335341 {
336- if (! isset ($ this ->globals [$ method ])) {
337- $ this ->globals [$ method ] = [];
342+ if (! isset ($ this ->globals [$ name ])) {
343+ $ this ->globals [$ name ] = [];
338344 }
339345
340346 // Don't populate ENV as it might contain
341347 // sensitive data that we don't want to get logged.
342- switch ($ method ) {
348+ switch ($ name ) {
343349 case 'get ' :
344350 $ this ->globals ['get ' ] = $ _GET ;
345351 break ;
0 commit comments