1 | <?php |
||
11 | class Session extends Parameter implements SessionInterface |
||
12 | { |
||
13 | /** @var \SessionHandlerInterface */ |
||
14 | protected $handler; |
||
15 | |||
16 | /** @var \Wandu\Http\Session\Configuration */ |
||
17 | protected $config; |
||
18 | |||
19 | /** @var string */ |
||
20 | protected $id; |
||
21 | |||
22 | 27 | public function __construct( |
|
23 | CookieJarInterface $cookieJar, |
||
24 | SessionHandlerInterface $handler, |
||
25 | Configuration $config = null, |
||
26 | ParameterInterface $fallback = null |
||
27 | ) { |
||
28 | 27 | $this->handler = $handler; |
|
29 | 27 | $this->config = $config ?: new Configuration(); |
|
30 | |||
31 | 27 | $sessionName = $this->config->getName(); |
|
32 | |||
33 | 27 | $this->id = $cookieJar->has($sessionName) |
|
34 | 26 | ? $cookieJar->get($sessionName) |
|
35 | 1 | : $this->config->getUniqueId(); |
|
36 | |||
37 | 27 | $params = @unserialize($handler->read($this->id)); |
|
38 | 27 | parent::__construct(isset($params) && is_array($params) ? $params : [], $fallback); |
|
39 | 27 | } |
|
40 | |||
41 | /** |
||
42 | * @return array |
||
43 | */ |
||
44 | 6 | public function toArray() |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 14 | public function get($name, $default = null, $isStrict = false) |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 5 | public function set($name, $value) |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | 3 | public function flash($name, $value) |
|
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | 10 | public function has($name) |
|
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | 3 | public function remove($name) |
|
110 | |||
111 | /** |
||
112 | * @param mixed $name |
||
113 | */ |
||
114 | 22 | protected function validNameArgument($name) |
|
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | 1 | public function offsetSet($offset, $value) |
|
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | 1 | public function offsetUnset($offset) |
|
139 | |||
140 | /** |
||
141 | * @param \Wandu\Http\Contracts\CookieJarInterface $cookieJar |
||
142 | */ |
||
143 | 1 | public function applyToCookieJar(CookieJarInterface $cookieJar) |
|
163 | } |
||
164 |