ci4
1<?php
2
3declare(strict_types=1);
4
5/**
6* This file is part of CodeIgniter 4 framework.
7*
8* (c) CodeIgniter Foundation <admin@codeigniter.com>
9*
10* For the full copyright and license information, please view
11* the LICENSE file that was distributed with this source code.
12*/
13
14namespace CodeIgniter;
15
16/**
17* Superglobals manipulation.
18*
19* @internal
20* @see \CodeIgniter\SuperglobalsTest
21*/
22final class Superglobals
23{
24private array $server;
25private array $get;
26
27public function __construct(?array $server = null, ?array $get = null)
28{
29$this->server = $server ?? $_SERVER;
30$this->get = $get ?? $_GET;
31}
32
33public function server(string $key): ?string
34{
35return $this->server[$key] ?? null;
36}
37
38public function setServer(string $key, string $value): void
39{
40$this->server[$key] = $value;
41$_SERVER[$key] = $value;
42}
43
44/**
45* @return array|string|null
46*/
47public function get(string $key)
48{
49return $this->get[$key] ?? null;
50}
51
52public function setGet(string $key, string $value): void
53{
54$this->get[$key] = $value;
55$_GET[$key] = $value;
56}
57
58public function setGetArray(array $array): void
59{
60$this->get = $array;
61$_GET = $array;
62}
63}
64