start
This commit is contained in:
33
src/App/Flash.php
Normal file
33
src/App/Flash.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App;
|
||||
|
||||
final class Flash
|
||||
{
|
||||
public function __construct(private SessionManager $session) {}
|
||||
|
||||
public function set(string $type, string $message): void
|
||||
{
|
||||
$this->session->start();
|
||||
$_SESSION['flash'] = [
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
];
|
||||
}
|
||||
|
||||
public function get(): ?array
|
||||
{
|
||||
$this->session->start();
|
||||
if (empty($_SESSION['flash']) || !is_array($_SESSION['flash'])) {
|
||||
return null;
|
||||
}
|
||||
$f = $_SESSION['flash'];
|
||||
unset($_SESSION['flash']);
|
||||
|
||||
return [
|
||||
'type' => (string)($f['type'] ?? 'info'),
|
||||
'message' => (string)($f['message'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user