Skip to content

Commit

Permalink
feat: allow Superglobals state changes from the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 12, 2023
1 parent b2e8c02 commit 239b2cc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions system/Superglobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,29 @@
*/
final class Superglobals
{
private array $server;
private array $get;

public function __construct(?array $server = null, ?array $get = null)
{
$this->server = $server ?? $_SERVER;
$this->get = $get ?? $_GET;
}

public function server(string $key): ?string
{
return $_SERVER[$key] ?? null;
return $this->server[$key] ?? null;
}

public function setServer(string $key, string $value): void
{
$_SERVER[$key] = $value;
$this->server[$key] = $value;
$_SERVER[$key] = $value;
}

public function setGetArray(array $array): void
{
$_GET = $array;
$this->get = $array;
$_GET = $array;
}
}

0 comments on commit 239b2cc

Please sign in to comment.