aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/Flash.php
blob: 6e8e78a714b4ecd6aa8e7ed83c33302ff5922314 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
    }
}