aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/Flash.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/Flash.php')
-rw-r--r--src/app/Flash.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/app/Flash.php b/src/app/Flash.php
new file mode 100644
index 0000000..6e8e78a
--- /dev/null
+++ b/src/app/Flash.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+// Flash messages: one-time session messages shown after a redirect.
+// Set a message before redirecting, display it on the next page load, then it's gone.
+
+namespace App;
+
+class Flash
+{
+ public static function set(string $type, string $message): void
+ {
+ $_SESSION['flash'] = ['type' => $type, 'message' => $message];
+ }
+
+ public static function get(): ?array
+ {
+ if (isset($_SESSION['flash'])) {
+ $flash = $_SESSION['flash'];
+ unset($_SESSION['flash']);
+ return $flash;
+ }
+ return null;
+ }
+}