Skip to content

Commit 1a95c89

Browse files
committed
feat: allow Superglobals state changes from the constructor
1 parent be7ca15 commit 1a95c89

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

system/Superglobals.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,37 @@
1818
*/
1919
final class Superglobals
2020
{
21+
private array $server;
22+
private array $get;
23+
24+
public function __construct(?array $server = null, ?array $get = null)
25+
{
26+
$this->server = $server ?? $_SERVER;
27+
$this->get = $get ?? $_GET;
28+
}
29+
2130
public function server(string $key): ?string
2231
{
23-
return $_SERVER[$key] ?? null;
32+
return $this->server[$key] ?? null;
2433
}
2534

2635
public function setServer(string $key, string $value): void
2736
{
28-
$_SERVER[$key] = $value;
37+
$this->server[$key] = $value;
38+
$_SERVER[$key] = $value;
39+
}
40+
41+
/**
42+
* @return array|string|null
43+
*/
44+
public function get(string $key)
45+
{
46+
return $this->get[$key] ?? null;
2947
}
3048

3149
public function setGetArray(array $array): void
3250
{
33-
$_GET = $array;
51+
$this->get = $array;
52+
$_GET = $array;
3453
}
3554
}

0 commit comments

Comments
 (0)