1 | <?php |
||
23 | final class LazySession implements SessionInterface |
||
24 | { |
||
25 | /** |
||
26 | * @internal do not access directly: use {@see LazySession::getRealSession} instead |
||
27 | * |
||
28 | * @var SessionInterface|null |
||
29 | */ |
||
30 | private $realSession; |
||
31 | |||
32 | /** |
||
33 | * @var callable |
||
34 | */ |
||
35 | private $sessionLoader; |
||
36 | |||
37 | /** |
||
38 | * Instantiation via __construct is not allowed, use {@see LazySession::fromContainerBuildingCallback} instead |
||
39 | */ |
||
40 | 50 | private function __construct() |
|
43 | |||
44 | /** |
||
45 | * @param callable $sessionLoader |
||
46 | * |
||
47 | * @return self |
||
48 | */ |
||
49 | 50 | public static function fromContainerBuildingCallback(callable $sessionLoader) : self |
|
57 | |||
58 | /** |
||
59 | * {@inheritDoc} |
||
60 | */ |
||
61 | 17 | public function set(string $key, $value) |
|
65 | |||
66 | /** |
||
67 | * {@inheritDoc} |
||
68 | */ |
||
69 | 4 | public function get(string $key, $default = null) |
|
73 | |||
74 | /** |
||
75 | * {@inheritDoc} |
||
76 | */ |
||
77 | 2 | public function remove(string $key) |
|
81 | |||
82 | /** |
||
83 | * {@inheritDoc} |
||
84 | */ |
||
85 | 4 | public function clear() |
|
89 | |||
90 | /** |
||
91 | * {@inheritDoc} |
||
92 | */ |
||
93 | 1 | public function has(string $key): bool |
|
97 | |||
98 | /** |
||
99 | * {@inheritDoc} |
||
100 | */ |
||
101 | 42 | public function hasChanged() : bool |
|
105 | |||
106 | /** |
||
107 | * {@inheritDoc} |
||
108 | */ |
||
109 | 39 | public function isEmpty() : bool |
|
113 | |||
114 | /** |
||
115 | * {@inheritDoc} |
||
116 | */ |
||
117 | 18 | public function jsonSerialize() |
|
121 | |||
122 | /** |
||
123 | * Get or initialize the session |
||
124 | * |
||
125 | * @return SessionInterface |
||
126 | */ |
||
127 | 46 | private function getRealSession() : SessionInterface |
|
131 | |||
132 | /** |
||
133 | * Type-safe wrapper that ensures that the given callback returns the expected type of object, when called |
||
134 | * |
||
135 | * @return SessionInterface |
||
136 | */ |
||
137 | 46 | private function loadSession() : SessionInterface |
|
143 | } |
||
144 |