@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | use chillerlan\Filereader\Drivers\FSDriverInterface; |
| 16 | 16 | use chillerlan\Traits\ContainerInterface; |
| 17 | 17 | |
| 18 | -class FileSessionHandler extends SessionHandlerAbstract{ |
|
| 18 | +class FileSessionHandler extends SessionHandlerAbstract { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @var \chillerlan\Filereader\Drivers\FSDriverInterface |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param \chillerlan\Traits\ContainerInterface $options |
| 29 | 29 | * @param \chillerlan\Filereader\Drivers\FSDriverInterface $FSdriver |
| 30 | 30 | */ |
| 31 | - public function __construct(ContainerInterface $options = null, FSDriverInterface $FSdriver){ |
|
| 31 | + public function __construct(ContainerInterface $options = null, FSDriverInterface $FSdriver) { |
|
| 32 | 32 | parent::__construct($options); |
| 33 | 33 | |
| 34 | 34 | // use the internal DiskDriver if no other filereader was given |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | public function destroy($session_id):bool{ |
| 45 | 45 | $file = $this->options->save_path.$this->options->filename_prefix.$session_id; |
| 46 | 46 | |
| 47 | - if($this->filereader->fileExists($file)) { |
|
| 47 | + if ($this->filereader->fileExists($file)) { |
|
| 48 | 48 | $this->filereader->deleteFile($file); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | public function gc($maxlifetime):bool{ |
| 56 | 56 | $files = $this->filereader->findFiles($this->options->save_path.$this->options->filename_prefix.'*'); |
| 57 | 57 | |
| 58 | - if(is_array($files)){ |
|
| 58 | + if (is_array($files)) { |
|
| 59 | 59 | |
| 60 | - foreach($files as $file){ |
|
| 60 | + foreach ($files as $file) { |
|
| 61 | 61 | |
| 62 | - if($this->filereader->fileModifyTime($file) + $maxlifetime < time() && $this->filereader->fileExists($file)){ |
|
| 62 | + if ($this->filereader->fileModifyTime($file) + $maxlifetime < time() && $this->filereader->fileExists($file)) { |
|
| 63 | 63 | $this->filereader->deleteFile($file); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | /** @inheritdoc */ |
| 74 | 74 | public function open($save_path, $name):bool{ |
| 75 | 75 | |
| 76 | - if(!$this->filereader->isWritable($save_path)){ |
|
| 76 | + if (!$this->filereader->isWritable($save_path)) { |
|
| 77 | 77 | return false; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | use chillerlan\Database\Database; |
| 16 | 16 | use chillerlan\Traits\ContainerInterface; |
| 17 | 17 | |
| 18 | -class DBSessionHandler extends SessionHandlerAbstract{ |
|
| 18 | +class DBSessionHandler extends SessionHandlerAbstract { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @var \chillerlan\Database\Database |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param \chillerlan\Traits\ContainerInterface $options |
| 29 | 29 | * @param \chillerlan\Database\Database $db |
| 30 | 30 | */ |
| 31 | - public function __construct(ContainerInterface $options = null, Database $db){ |
|
| 31 | + public function __construct(ContainerInterface $options = null, Database $db) { |
|
| 32 | 32 | parent::__construct($options); |
| 33 | 33 | |
| 34 | 34 | $this->db = $db->connect(); |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | ->where('id', $session_id) |
| 76 | 76 | ->query(); |
| 77 | 77 | |
| 78 | - try{ |
|
| 78 | + try { |
|
| 79 | 79 | |
| 80 | - if(!$q || !isset($q[0])){ |
|
| 80 | + if (!$q || !isset($q[0])) { |
|
| 81 | 81 | return ''; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | return $this->options->use_encryption ? $this->decrypt($q[0]->data) : $q[0]->data; |
| 85 | 85 | } |
| 86 | - catch(\Exception $e){ |
|
| 86 | + catch (\Exception $e) { |
|
| 87 | 87 | throw new SessionHandlerException($e->getMessage()); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -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 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @param \chillerlan\Traits\ContainerInterface $options |
| 37 | 37 | */ |
| 38 | - public function __construct(ContainerInterface $options = null){ |
|
| 38 | + public function __construct(ContainerInterface $options = null) { |
|
| 39 | 39 | $this->options = $options ?? new SessionHandlerOptions; |
| 40 | 40 | $this->set_session_options(); |
| 41 | 41 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | setcookie( |
| 53 | 53 | session_name(), |
| 54 | 54 | session_id(), |
| 55 | - time()+$this->options->cookie_lifetime, |
|
| 55 | + time() + $this->options->cookie_lifetime, |
|
| 56 | 56 | $this->options->cookie_path, |
| 57 | 57 | $cookie_params['domain'] |
| 58 | 58 | ); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** @inheritdoc */ |
| 75 | - public function get(string $name){ |
|
| 75 | + public function get(string $name) { |
|
| 76 | 76 | return $_SESSION[$name] ?? null; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | protected function encrypt(string &$data):string { |
| 105 | 105 | |
| 106 | - if(function_exists('sodium_crypto_secretbox')){ |
|
| 106 | + if (function_exists('sodium_crypto_secretbox')) { |
|
| 107 | 107 | $box = sodium_crypto_secretbox($data, $this::SESSION_NONCE, sodium_hex2bin($this->options->sessionCryptoKey)); |
| 108 | 108 | |
| 109 | 109 | sodium_memzero($data); |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | protected function decrypt(string $box):string { |
| 124 | 124 | |
| 125 | - if(function_exists('sodium_crypto_secretbox_open')){ |
|
| 125 | + if (function_exists('sodium_crypto_secretbox_open')) { |
|
| 126 | 126 | return sodium_crypto_secretbox_open(sodium_hex2bin($box), $this::SESSION_NONCE, sodium_hex2bin($this->options->sessionCryptoKey)); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | /** |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | - protected function set_session_options(){ |
|
| 135 | + protected function set_session_options() { |
|
| 136 | 136 | |
| 137 | - if(is_writable($this->options->save_path)){ |
|
| 137 | + if (is_writable($this->options->save_path)) { |
|
| 138 | 138 | ini_set('session.save_path', $this->options->save_path); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | ini_set('session.cookie_lifetime', 0); |
| 153 | 153 | # ini_set('session.referer_check', ''); |
| 154 | 154 | |
| 155 | - if(PHP_VERSION_ID < 70100){ |
|
| 155 | + if (PHP_VERSION_ID < 70100) { |
|
| 156 | 156 | ini_set('session.hash_bits_per_character', 6); |
| 157 | 157 | |
| 158 | - if(in_array($this->options->hash_algo, hash_algos())){ |
|
| 158 | + if (in_array($this->options->hash_algo, hash_algos())) { |
|
| 159 | 159 | ini_set('session.hash_function', $this->options->hash_algo); |
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | - else{ |
|
| 162 | + else { |
|
| 163 | 163 | ini_set('session.sid_bits_per_character', 6); |
| 164 | 164 | ini_set('session.sid_length', 128); |
| 165 | 165 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\Session; |
| 14 | 14 | |
| 15 | -interface SessionInterface{ |
|
| 15 | +interface SessionInterface { |
|
| 16 | 16 | |
| 17 | 17 | 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"; |
| 18 | 18 | |
@@ -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'; |
@@ -26,6 +26,6 @@ |
||
| 26 | 26 | * @property bool $use_encryption |
| 27 | 27 | * @property string $sessionCryptoKey |
| 28 | 28 | */ |
| 29 | -class SessionHandlerOptions extends ContainerAbstract{ |
|
| 29 | +class SessionHandlerOptions extends ContainerAbstract { |
|
| 30 | 30 | use SessionHandlerOptionsTrait; |
| 31 | 31 | } |