|
14 | 14 | namespace CodeIgniter\HTTP; |
15 | 15 |
|
16 | 16 | use CodeIgniter\Exceptions\ConfigException; |
| 17 | +use CodeIgniter\Superglobals; |
17 | 18 | use CodeIgniter\Validation\FormatRules; |
18 | 19 | use Config\App; |
19 | 20 |
|
@@ -43,13 +44,34 @@ trait RequestTrait |
43 | 44 | */ |
44 | 45 | protected $ipAddress = ''; |
45 | 46 |
|
| 47 | + /** |
| 48 | + * Superglobals access wrapper. |
| 49 | + * |
| 50 | + * @var Superglobals|null |
| 51 | + */ |
| 52 | + protected $superglobals; |
| 53 | + |
46 | 54 | /** |
47 | 55 | * Stores values we've retrieved from PHP globals. |
48 | 56 | * |
49 | 57 | * @var array{get?: array, post?: array, request?: array, cookie?: array, server?: array} |
| 58 | + * |
| 59 | + * @deprecated 4.7.0 Use $superglobals instead |
50 | 60 | */ |
51 | 61 | protected $globals = []; |
52 | 62 |
|
| 63 | + /** |
| 64 | + * Get the Superglobals service instance. |
| 65 | + */ |
| 66 | + protected function getSuperglobals(): Superglobals |
| 67 | + { |
| 68 | + if ($this->superglobals === null) { |
| 69 | + $this->superglobals = service('superglobals'); |
| 70 | + } |
| 71 | + |
| 72 | + return $this->superglobals; |
| 73 | + } |
| 74 | + |
53 | 75 | /** |
54 | 76 | * Gets the user's IP address. |
55 | 77 | * |
@@ -231,8 +253,12 @@ public function getEnv($index = null, $filter = null, $flags = null) |
231 | 253 | */ |
232 | 254 | public function setGlobal(string $name, $value) |
233 | 255 | { |
| 256 | + // Keep BC with $globals array |
234 | 257 | $this->globals[$name] = $value; |
235 | 258 |
|
| 259 | + // Also update Superglobals via service |
| 260 | + $this->getSuperglobals()->setGlobalArray($name, $value); |
| 261 | + |
236 | 262 | return $this; |
237 | 263 | } |
238 | 264 |
|
@@ -342,35 +368,16 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f |
342 | 368 | * @param 'cookie'|'get'|'post'|'request'|'server' $name Superglobal name (lowercase) |
343 | 369 | * |
344 | 370 | * @return void |
| 371 | + * |
| 372 | + * @deprecated 4.7.0 No longer needs to be called explicitly. Used internally to maintain BC with $globals. |
345 | 373 | */ |
346 | 374 | protected function populateGlobals(string $name) |
347 | 375 | { |
348 | 376 | if (! isset($this->globals[$name])) { |
349 | 377 | $this->globals[$name] = []; |
350 | 378 | } |
351 | 379 |
|
352 | | - // Don't populate ENV as it might contain |
353 | | - // sensitive data that we don't want to get logged. |
354 | | - switch ($name) { |
355 | | - case 'get': |
356 | | - $this->globals['get'] = $_GET; |
357 | | - break; |
358 | | - |
359 | | - case 'post': |
360 | | - $this->globals['post'] = $_POST; |
361 | | - break; |
362 | | - |
363 | | - case 'request': |
364 | | - $this->globals['request'] = $_REQUEST; |
365 | | - break; |
366 | | - |
367 | | - case 'cookie': |
368 | | - $this->globals['cookie'] = $_COOKIE; |
369 | | - break; |
370 | | - |
371 | | - case 'server': |
372 | | - $this->globals['server'] = $_SERVER; |
373 | | - break; |
374 | | - } |
| 380 | + // Get data from Superglobals service instead of direct access |
| 381 | + $this->globals[$name] = $this->getSuperglobals()->getGlobalArray($name); |
375 | 382 | } |
376 | 383 | } |
0 commit comments