@@ -24,7 +24,7 @@ |
||
24 | 24 | { |
25 | 25 | public function tearDown(): void |
26 | 26 | { |
27 | - if ((int)session_status() === PHP_SESSION_ACTIVE) { |
|
27 | + if ((int)session_status() === PHP_SESSION_ACTIVE){ |
|
28 | 28 | session_abort(); |
29 | 29 | } |
30 | 30 | } |
@@ -24,7 +24,8 @@ |
||
24 | 24 | { |
25 | 25 | public function tearDown(): void |
26 | 26 | { |
27 | - if ((int)session_status() === PHP_SESSION_ACTIVE) { |
|
27 | + if ((int)session_status() === PHP_SESSION_ACTIVE) |
|
28 | + { |
|
28 | 29 | session_abort(); |
29 | 30 | } |
30 | 31 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | public function tearDown(): void |
53 | 53 | { |
54 | - if ((int)session_status() === PHP_SESSION_ACTIVE) { |
|
54 | + if ((int)session_status() === PHP_SESSION_ACTIVE){ |
|
55 | 55 | session_abort(); |
56 | 56 | } |
57 | 57 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $this->assertSame('default', $section->getName()); |
126 | 126 | |
127 | 127 | $section->set('key', 'value'); |
128 | - foreach ($section as $key => $value) { |
|
128 | + foreach ($section as $key => $value){ |
|
129 | 129 | $this->assertSame('key', $key); |
130 | 130 | $this->assertSame('value', $value); |
131 | 131 | } |
@@ -51,7 +51,8 @@ discard block |
||
51 | 51 | |
52 | 52 | public function tearDown(): void |
53 | 53 | { |
54 | - if ((int)session_status() === PHP_SESSION_ACTIVE) { |
|
54 | + if ((int)session_status() === PHP_SESSION_ACTIVE) |
|
55 | + { |
|
55 | 56 | session_abort(); |
56 | 57 | } |
57 | 58 | } |
@@ -125,7 +126,8 @@ discard block |
||
125 | 126 | $this->assertSame('default', $section->getName()); |
126 | 127 | |
127 | 128 | $section->set('key', 'value'); |
128 | - foreach ($section as $key => $value) { |
|
129 | + foreach ($section as $key => $value) |
|
130 | + { |
|
129 | 131 | $this->assertSame('key', $key); |
130 | 132 | $this->assertSame('value', $value); |
131 | 133 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function get(string $name, $default = null) |
129 | 129 | { |
130 | - if (!$this->has($name)) { |
|
130 | + if (!$this->has($name)){ |
|
131 | 131 | return $default; |
132 | 132 | } |
133 | 133 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | $this->session->resume(); |
204 | 204 | |
205 | - if (!isset($_SESSION[$this->name])) { |
|
205 | + if (!isset($_SESSION[$this->name])){ |
|
206 | 206 | $_SESSION[$this->name] = []; |
207 | 207 | } |
208 | 208 | } |
@@ -127,7 +127,8 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function get(string $name, $default = null) |
129 | 129 | { |
130 | - if (!$this->has($name)) { |
|
130 | + if (!$this->has($name)) |
|
131 | + { |
|
131 | 132 | return $default; |
132 | 133 | } |
133 | 134 | |
@@ -202,7 +203,8 @@ discard block |
||
202 | 203 | { |
203 | 204 | $this->session->resume(); |
204 | 205 | |
205 | - if (!isset($_SESSION[$this->name])) { |
|
206 | + if (!isset($_SESSION[$this->name])) |
|
207 | + { |
|
206 | 208 | $_SESSION[$this->name] = []; |
207 | 209 | } |
208 | 210 | } |
@@ -62,8 +62,8 @@ |
||
62 | 62 | */ |
63 | 63 | public function gc($maxlifetime): void |
64 | 64 | { |
65 | - foreach ($this->files->getFiles($this->directory) as $filename) { |
|
66 | - if ($this->files->time($filename) < time() - $maxlifetime) { |
|
65 | + foreach ($this->files->getFiles($this->directory) as $filename){ |
|
66 | + if ($this->files->time($filename) < time() - $maxlifetime){ |
|
67 | 67 | $this->files->delete($filename); |
68 | 68 | } |
69 | 69 | } |
@@ -62,8 +62,10 @@ |
||
62 | 62 | */ |
63 | 63 | public function gc($maxlifetime): void |
64 | 64 | { |
65 | - foreach ($this->files->getFiles($this->directory) as $filename) { |
|
66 | - if ($this->files->time($filename) < time() - $maxlifetime) { |
|
65 | + foreach ($this->files->getFiles($this->directory) as $filename) |
|
66 | + { |
|
67 | + if ($this->files->time($filename) < time() - $maxlifetime) |
|
68 | + { |
|
67 | 69 | $this->files->delete($filename); |
68 | 70 | } |
69 | 71 | } |
@@ -48,15 +48,15 @@ |
||
48 | 48 | */ |
49 | 49 | public function initSession(string $clientSignature, string $id = null): SessionInterface |
50 | 50 | { |
51 | - if ((int)session_status() === PHP_SESSION_ACTIVE) { |
|
51 | + if ((int)session_status() === PHP_SESSION_ACTIVE){ |
|
52 | 52 | throw new MultipleSessionException('Unable to initiate session, session already started'); |
53 | 53 | } |
54 | 54 | |
55 | 55 | //Initiating proper session handler |
56 | - if ($this->config->getHandler() !== null) { |
|
57 | - try { |
|
56 | + if ($this->config->getHandler() !== null){ |
|
57 | + try{ |
|
58 | 58 | $handler = $this->config->getHandler()->resolve($this->factory); |
59 | - } catch (\Throwable | ContainerExceptionInterface $e) { |
|
59 | + }catch (\Throwable | ContainerExceptionInterface $e){ |
|
60 | 60 | throw new SessionException($e->getMessage(), $e->getCode(), $e); |
61 | 61 | } |
62 | 62 |
@@ -48,15 +48,20 @@ |
||
48 | 48 | */ |
49 | 49 | public function initSession(string $clientSignature, string $id = null): SessionInterface |
50 | 50 | { |
51 | - if ((int)session_status() === PHP_SESSION_ACTIVE) { |
|
51 | + if ((int)session_status() === PHP_SESSION_ACTIVE) |
|
52 | + { |
|
52 | 53 | throw new MultipleSessionException('Unable to initiate session, session already started'); |
53 | 54 | } |
54 | 55 | |
55 | 56 | //Initiating proper session handler |
56 | - if ($this->config->getHandler() !== null) { |
|
57 | - try { |
|
57 | + if ($this->config->getHandler() !== null) |
|
58 | + { |
|
59 | + try |
|
60 | + { |
|
58 | 61 | $handler = $this->config->getHandler()->resolve($this->factory); |
59 | - } catch (\Throwable | ContainerExceptionInterface $e) { |
|
62 | + } |
|
63 | + catch (\Throwable | ContainerExceptionInterface $e) |
|
64 | + { |
|
60 | 65 | throw new SessionException($e->getMessage(), $e->getCode(), $e); |
61 | 66 | } |
62 | 67 |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $this->clientSignature = $clientSignature; |
73 | 73 | $this->lifetime = $lifetime; |
74 | 74 | |
75 | - if (!empty($id) && $this->validID($id)) { |
|
75 | + if (!empty($id) && $this->validID($id)){ |
|
76 | 76 | $this->id = $id; |
77 | 77 | } |
78 | 78 | } |
@@ -103,24 +103,24 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function resume(): void |
105 | 105 | { |
106 | - if ($this->isStarted()) { |
|
106 | + if ($this->isStarted()){ |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | - if (!empty($this->id)) { |
|
110 | + if (!empty($this->id)){ |
|
111 | 111 | session_id($this->id); |
112 | - } else { |
|
112 | + }else{ |
|
113 | 113 | // always new id |
114 | 114 | session_id(session_create_id()); |
115 | 115 | } |
116 | 116 | |
117 | - try { |
|
117 | + try{ |
|
118 | 118 | session_start(['use_cookies' => false]); |
119 | - } catch (\Throwable $e) { |
|
119 | + }catch (\Throwable $e){ |
|
120 | 120 | throw new SessionException('Unable to start session', $e->getCode(), $e); |
121 | 121 | } |
122 | 122 | |
123 | - if (empty($this->id)) { |
|
123 | + if (empty($this->id)){ |
|
124 | 124 | //Sign newly created session |
125 | 125 | $_SESSION[self::CLIENT_SIGNATURE] = $this->clientSignature; |
126 | 126 | $_SESSION[self::SESSION_CREATED] = time(); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $this->started = true; |
132 | 132 | |
133 | 133 | //Ensure that session is valid |
134 | - if (!$this->validSession()) { |
|
134 | + if (!$this->validSession()){ |
|
135 | 135 | $this->invalidateSession(); |
136 | 136 | } |
137 | 137 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function commit(): bool |
172 | 172 | { |
173 | - if (!$this->isStarted()) { |
|
173 | + if (!$this->isStarted()){ |
|
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function abort(): bool |
187 | 187 | { |
188 | - if (!$this->isStarted()) { |
|
188 | + if (!$this->isStarted()){ |
|
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
@@ -228,17 +228,17 @@ discard block |
||
228 | 228 | if ( |
229 | 229 | !array_key_exists(self::CLIENT_SIGNATURE, $_SESSION) |
230 | 230 | || !array_key_exists(self::SESSION_CREATED, $_SESSION) |
231 | - ) { |
|
231 | + ){ |
|
232 | 232 | //Missing session signature or timestamp! |
233 | 233 | return false; |
234 | 234 | } |
235 | 235 | |
236 | - if ($_SESSION[self::SESSION_CREATED] < time() - $this->lifetime) { |
|
236 | + if ($_SESSION[self::SESSION_CREATED] < time() - $this->lifetime){ |
|
237 | 237 | //Session expired |
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | |
241 | - if (!hash_equals($_SESSION[self::CLIENT_SIGNATURE], $this->clientSignature)) { |
|
241 | + if (!hash_equals($_SESSION[self::CLIENT_SIGNATURE], $this->clientSignature)){ |
|
242 | 242 | //Signatures do not match |
243 | 243 | return false; |
244 | 244 | } |
@@ -72,7 +72,8 @@ discard block |
||
72 | 72 | $this->clientSignature = $clientSignature; |
73 | 73 | $this->lifetime = $lifetime; |
74 | 74 | |
75 | - if (!empty($id) && $this->validID($id)) { |
|
75 | + if (!empty($id) && $this->validID($id)) |
|
76 | + { |
|
76 | 77 | $this->id = $id; |
77 | 78 | } |
78 | 79 | } |
@@ -103,24 +104,32 @@ discard block |
||
103 | 104 | */ |
104 | 105 | public function resume(): void |
105 | 106 | { |
106 | - if ($this->isStarted()) { |
|
107 | + if ($this->isStarted()) |
|
108 | + { |
|
107 | 109 | return; |
108 | 110 | } |
109 | 111 | |
110 | - if (!empty($this->id)) { |
|
112 | + if (!empty($this->id)) |
|
113 | + { |
|
111 | 114 | session_id($this->id); |
112 | - } else { |
|
115 | + } |
|
116 | + else |
|
117 | + { |
|
113 | 118 | // always new id |
114 | 119 | session_id(session_create_id()); |
115 | 120 | } |
116 | 121 | |
117 | - try { |
|
122 | + try |
|
123 | + { |
|
118 | 124 | session_start(['use_cookies' => false]); |
119 | - } catch (\Throwable $e) { |
|
125 | + } |
|
126 | + catch (\Throwable $e) |
|
127 | + { |
|
120 | 128 | throw new SessionException('Unable to start session', $e->getCode(), $e); |
121 | 129 | } |
122 | 130 | |
123 | - if (empty($this->id)) { |
|
131 | + if (empty($this->id)) |
|
132 | + { |
|
124 | 133 | //Sign newly created session |
125 | 134 | $_SESSION[self::CLIENT_SIGNATURE] = $this->clientSignature; |
126 | 135 | $_SESSION[self::SESSION_CREATED] = time(); |
@@ -131,7 +140,8 @@ discard block |
||
131 | 140 | $this->started = true; |
132 | 141 | |
133 | 142 | //Ensure that session is valid |
134 | - if (!$this->validSession()) { |
|
143 | + if (!$this->validSession()) |
|
144 | + { |
|
135 | 145 | $this->invalidateSession(); |
136 | 146 | } |
137 | 147 | } |
@@ -170,7 +180,8 @@ discard block |
||
170 | 180 | */ |
171 | 181 | public function commit(): bool |
172 | 182 | { |
173 | - if (!$this->isStarted()) { |
|
183 | + if (!$this->isStarted()) |
|
184 | + { |
|
174 | 185 | return false; |
175 | 186 | } |
176 | 187 | |
@@ -185,7 +196,8 @@ discard block |
||
185 | 196 | */ |
186 | 197 | public function abort(): bool |
187 | 198 | { |
188 | - if (!$this->isStarted()) { |
|
199 | + if (!$this->isStarted()) |
|
200 | + { |
|
189 | 201 | return false; |
190 | 202 | } |
191 | 203 | |
@@ -233,12 +245,14 @@ discard block |
||
233 | 245 | return false; |
234 | 246 | } |
235 | 247 | |
236 | - if ($_SESSION[self::SESSION_CREATED] < time() - $this->lifetime) { |
|
248 | + if ($_SESSION[self::SESSION_CREATED] < time() - $this->lifetime) |
|
249 | + { |
|
237 | 250 | //Session expired |
238 | 251 | return false; |
239 | 252 | } |
240 | 253 | |
241 | - if (!hash_equals($_SESSION[self::CLIENT_SIGNATURE], $this->clientSignature)) { |
|
254 | + if (!hash_equals($_SESSION[self::CLIENT_SIGNATURE], $this->clientSignature)) |
|
255 | + { |
|
242 | 256 | //Signatures do not match |
243 | 257 | return false; |
244 | 258 | } |
@@ -64,15 +64,15 @@ |
||
64 | 64 | */ |
65 | 65 | public function getHandler(): ?Autowire |
66 | 66 | { |
67 | - if (empty($this->config['handler'])) { |
|
67 | + if (empty($this->config['handler'])){ |
|
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | |
71 | - if ($this->config['handler'] instanceof Autowire) { |
|
71 | + if ($this->config['handler'] instanceof Autowire){ |
|
72 | 72 | return $this->config['handler']; |
73 | 73 | } |
74 | 74 | |
75 | - if (class_exists($this->config['handler'])) { |
|
75 | + if (class_exists($this->config['handler'])){ |
|
76 | 76 | return new Autowire($this->config['handler']); |
77 | 77 | } |
78 | 78 |
@@ -64,15 +64,18 @@ |
||
64 | 64 | */ |
65 | 65 | public function getHandler(): ?Autowire |
66 | 66 | { |
67 | - if (empty($this->config['handler'])) { |
|
67 | + if (empty($this->config['handler'])) |
|
68 | + { |
|
68 | 69 | return null; |
69 | 70 | } |
70 | 71 | |
71 | - if ($this->config['handler'] instanceof Autowire) { |
|
72 | + if ($this->config['handler'] instanceof Autowire) |
|
73 | + { |
|
72 | 74 | return $this->config['handler']; |
73 | 75 | } |
74 | 76 | |
75 | - if (class_exists($this->config['handler'])) { |
|
77 | + if (class_exists($this->config['handler'])) |
|
78 | + { |
|
76 | 79 | return new Autowire($this->config['handler']); |
77 | 80 | } |
78 | 81 |