summaryrefslogtreecommitdiff
path: root/src/DTS/Session.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/DTS/Session.php')
-rw-r--r--src/DTS/Session.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/DTS/Session.php b/src/DTS/Session.php
new file mode 100644
index 0000000..956f4e5
--- /dev/null
+++ b/src/DTS/Session.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+namespace DTS;
+
+class Session
+{
+ private static ?self $instance = null;
+
+ private array $session;
+
+ public static function getInstance()
+ {
+ if (!self::$instance) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ private function __construct()
+ {
+ session_start();
+
+ foreach ($_SESSION as $key => $value) {
+ $this->session[$key] = $value;
+ unset($_SESSION[$key]);
+ }
+ }
+
+ public function set(string $key, string $value): void
+ {
+ $this->session[$key] = $_SESSION[$key] = $value;
+ }
+
+ public function get(string $key): ?string
+ {
+ return $this->session[$key] ?? null;
+ }
+}