@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Session; |
14 | 14 | |
15 | -class SessionHandlerException extends \Exception{} |
|
15 | +class SessionHandlerException extends \Exception {} |
@@ -82,8 +82,7 @@ |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | return $this->options->use_encryption ? $this->decrypt($q[0]->data) : $q[0]->data; |
85 | - } |
|
86 | - catch(\Exception $e){ |
|
85 | + } catch(\Exception $e){ |
|
87 | 86 | throw new SessionHandlerException($e->getMessage()); |
88 | 87 | } |
89 | 88 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use chillerlan\Settings\SettingsContainerInterface; |
17 | 17 | use Psr\Log\LoggerInterface; |
18 | 18 | |
19 | -class DBSessionHandler extends SessionHandlerAbstract{ |
|
19 | +class DBSessionHandler extends SessionHandlerAbstract { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var \chillerlan\Database\Database |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param \chillerlan\Settings\SettingsContainerInterface $options |
31 | 31 | * @param \Psr\Log\LoggerInterface|null $logger |
32 | 32 | */ |
33 | - public function __construct(Database $db, SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
33 | + public function __construct(Database $db, SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
34 | 34 | parent::__construct($options, $logger); |
35 | 35 | |
36 | 36 | $this->db = $db->connect(); |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | ->where('id', $session_id) |
83 | 83 | ->query(); |
84 | 84 | |
85 | - try{ |
|
85 | + try { |
|
86 | 86 | |
87 | - if(!$q || !isset($q[0])){ |
|
87 | + if (!$q || !isset($q[0])) { |
|
88 | 88 | return ''; |
89 | 89 | } |
90 | 90 | |
91 | 91 | return $this->options->use_encryption ? $this->decrypt($q[0]->data) : $q[0]->data; |
92 | 92 | } |
93 | - catch(\Exception $e){ |
|
93 | + catch (\Exception $e) { |
|
94 | 94 | throw new SessionHandlerException($e->getMessage()); |
95 | 95 | } |
96 | 96 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Session; |
14 | 14 | |
15 | -trait SessionHandlerOptionsTrait{ |
|
15 | +trait SessionHandlerOptionsTrait { |
|
16 | 16 | |
17 | 17 | protected $filename_prefix = 'SESSION_'; |
18 | 18 | protected $session_name = 'SESSIONID'; |
@@ -31,7 +31,7 @@ |
||
31 | 31 | 'password' => $env->get('DB_PASSWORD'), |
32 | 32 | ]; |
33 | 33 | |
34 | -$options = new class($options) extends \chillerlan\Settings\SettingsContainerAbstract{ |
|
34 | +$options = new class($options) extends \chillerlan\Settings\SettingsContainerAbstract { |
|
35 | 35 | use DatabaseOptionsTrait, SessionHandlerOptionsTrait; |
36 | 36 | }; |
37 | 37 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use SessionHandlerInterface; |
16 | 16 | |
17 | -interface SessionInterface extends SessionHandlerInterface{ |
|
17 | +interface SessionInterface extends SessionHandlerInterface { |
|
18 | 18 | |
19 | 19 | const SESSION_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"; |
20 | 20 |
@@ -26,6 +26,6 @@ |
||
26 | 26 | * @property bool $use_encryption |
27 | 27 | * @property string $sessionCryptoKey |
28 | 28 | */ |
29 | -class SessionHandlerOptions extends SettingsContainerAbstract{ |
|
29 | +class SessionHandlerOptions extends SettingsContainerAbstract { |
|
30 | 30 | use SessionHandlerOptionsTrait; |
31 | 31 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param \chillerlan\Settings\SettingsContainerInterface $options |
36 | 36 | * @param \Psr\Log\LoggerInterface|null $logger |
37 | 37 | */ |
38 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
38 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
39 | 39 | $this->options = $options ?? new SessionHandlerOptions; |
40 | 40 | $this->logger = $logger ?? new NullLogger; |
41 | 41 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function start():SessionInterface{ |
52 | 52 | |
53 | - if($this->active()){ |
|
53 | + if ($this->active()) { |
|
54 | 54 | throw new SessionHandlerException('session already running'); |
55 | 55 | } |
56 | 56 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | /** @inheritdoc */ |
74 | 74 | public function end():SessionInterface{ |
75 | 75 | |
76 | - if($this->active()){ |
|
76 | + if ($this->active()) { |
|
77 | 77 | \session_regenerate_id(true); |
78 | 78 | \setcookie(session_name(), '', 0, $this->options->cookie_path); |
79 | 79 | \session_unset(); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | /** @inheritdoc */ |
93 | - public function get(string $name){ |
|
93 | + public function get(string $name) { |
|
94 | 94 | return $_SESSION[$name] ?? null; |
95 | 95 | } |
96 | 96 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | protected function encrypt(string &$data):string { |
123 | 123 | |
124 | - if(\function_exists('sodium_crypto_secretbox')){ |
|
124 | + if (\function_exists('sodium_crypto_secretbox')) { |
|
125 | 125 | $box = \sodium_crypto_secretbox($data, $this::SESSION_NONCE, \sodium_hex2bin($this->options->sessionCryptoKey)); |
126 | 126 | |
127 | 127 | \sodium_memzero($data); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function decrypt(string $box):string { |
142 | 142 | |
143 | - if(\function_exists('sodium_crypto_secretbox_open')){ |
|
143 | + if (\function_exists('sodium_crypto_secretbox_open')) { |
|
144 | 144 | return \sodium_crypto_secretbox_open(\sodium_hex2bin($box), $this::SESSION_NONCE, \sodium_hex2bin($this->options->sessionCryptoKey)); |
145 | 145 | } |
146 | 146 | |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | public function setOptions(SettingsContainerInterface $options):SessionInterface{ |
156 | 156 | |
157 | 157 | // end an active session before setting new options |
158 | - if($this->active()){ |
|
158 | + if ($this->active()) { |
|
159 | 159 | $this->end(); |
160 | 160 | } |
161 | 161 | |
162 | - if(\is_writable($options->save_path)){ |
|
162 | + if (\is_writable($options->save_path)) { |
|
163 | 163 | \ini_set('session.save_path', $options->save_path); |
164 | 164 | } |
165 | 165 |