-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFallbackSession.php
37 lines (32 loc) · 1.1 KB
/
FallbackSession.php
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
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace Flasher\Symfony\Storage;
/**
* FallbackSession - In-memory session storage fallback.
*
* This class provides a simple in-memory storage mechanism that can be used
* when the regular Symfony session is not available. It stores values in a
* static array, making them available for the duration of the request.
*
* Design patterns:
* - Null Object Pattern: Provides a non-failing alternative to a missing session
* - In-Memory Repository: Stores data in memory as a simple alternative to persistence
* - Singleton-like Pattern: Uses a static storage array shared across instances
*/
final class FallbackSession implements FallbackSessionInterface
{
/**
* In-memory storage for session data.
*
* @var array<string, mixed>
*/
private static array $storage = [];
public function get(string $name, mixed $default = null): mixed
{
return \array_key_exists($name, self::$storage) ? self::$storage[$name] : $default;
}
public function set(string $name, mixed $value): void
{
self::$storage[$name] = $value;
}
}