From 239b2cc4c8c0085f791cf5a79b1306476a30c825 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 12 Jul 2023 09:50:40 +0900 Subject: [PATCH] feat: allow Superglobals state changes from the constructor --- system/Superglobals.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/system/Superglobals.php b/system/Superglobals.php index 65ab800e98f3..4c2f7bd6e445 100644 --- a/system/Superglobals.php +++ b/system/Superglobals.php @@ -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; } }