@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param \chillerlan\Session\SessionHandlerOptions $options |
| 40 | 40 | */ |
| 41 | - public function __construct(SessionHandlerOptions $options = null){ |
|
| 41 | + public function __construct(SessionHandlerOptions $options = null) { |
|
| 42 | 42 | $this->set_options($options); |
| 43 | 43 | |
| 44 | 44 | session_set_save_handler($this, true); |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @return void |
| 49 | 49 | */ |
| 50 | - public function start(){ |
|
| 50 | + public function start() { |
|
| 51 | 51 | $cookie_params = session_get_cookie_params(); |
| 52 | 52 | |
| 53 | 53 | session_start(); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | setcookie( |
| 57 | 57 | session_name(), |
| 58 | 58 | session_id(), |
| 59 | - time()+$this->options->cookie_lifetime, |
|
| 59 | + time() + $this->options->cookie_lifetime, |
|
| 60 | 60 | $this->options->cookie_path, |
| 61 | 61 | $cookie_params['domain'] |
| 62 | 62 | ); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @return void |
| 67 | 67 | */ |
| 68 | - public function end(){ |
|
| 68 | + public function end() { |
|
| 69 | 69 | session_regenerate_id(true); |
| 70 | 70 | setcookie(session_name(), '', 0, $this->options->cookie_path); |
| 71 | 71 | session_unset(); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | public function encrypt(string $data):string { |
| 83 | 83 | $nonce = random_bytes(24); |
| 84 | 84 | |
| 85 | - if($this->options->use_encryption && function_exists('sodium_crypto_secretbox')){ |
|
| 85 | + if ($this->options->use_encryption && function_exists('sodium_crypto_secretbox')) { |
|
| 86 | 86 | return sodium_bin2hex($nonce.sodium_crypto_secretbox($data, $nonce, sodium_hex2bin($this->key))); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function decrypt(string $box):string { |
| 99 | 99 | |
| 100 | - if($this->options->use_encryption && function_exists('sodium_crypto_secretbox_open')){ |
|
| 100 | + if ($this->options->use_encryption && function_exists('sodium_crypto_secretbox_open')) { |
|
| 101 | 101 | $box = sodium_hex2bin($box); |
| 102 | 102 | |
| 103 | 103 | return sodium_crypto_secretbox_open(substr($box, 24), substr($box, 0, 24), sodium_hex2bin($this->key)); |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return void |
| 113 | 113 | */ |
| 114 | - protected function set_options(SessionHandlerOptions $options = null){ |
|
| 114 | + protected function set_options(SessionHandlerOptions $options = null) { |
|
| 115 | 115 | $this->options = $options ?? new SessionHandlerOptions; |
| 116 | 116 | |
| 117 | - if(!is_null($this->options->save_path)){ |
|
| 117 | + if (!is_null($this->options->save_path)) { |
|
| 118 | 118 | $this->options->save_path .= |
| 119 | 119 | !in_array(substr($this->options->save_path, -1), ['/', '\\']) |
| 120 | 120 | ? DIRECTORY_SEPARATOR |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | ini_set('session.cookie_lifetime', 0); |
| 138 | 138 | # ini_set('session.referer_check', ''); |
| 139 | 139 | |
| 140 | - if(PHP_VERSION_ID < 70100){ |
|
| 140 | + if (PHP_VERSION_ID < 70100) { |
|
| 141 | 141 | ini_set('session.hash_bits_per_character', 6); |
| 142 | 142 | |
| 143 | - if(in_array($this->options->hash_algo, hash_algos())){ |
|
| 143 | + if (in_array($this->options->hash_algo, hash_algos())) { |
|
| 144 | 144 | ini_set('session.hash_function', $this->options->hash_algo); |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | - else{ |
|
| 147 | + else { |
|
| 148 | 148 | ini_set('session.sid_bits_per_character', 6); |
| 149 | 149 | ini_set('session.sid_length', 128); |
| 150 | 150 | } |
@@ -143,8 +143,7 @@ |
||
| 143 | 143 | if(in_array($this->options->hash_algo, hash_algos())){ |
| 144 | 144 | ini_set('session.hash_function', $this->options->hash_algo); |
| 145 | 145 | } |
| 146 | - } |
|
| 147 | - else{ |
|
| 146 | + } else{ |
|
| 148 | 147 | ini_set('session.sid_bits_per_character', 6); |
| 149 | 148 | ini_set('session.sid_length', 128); |
| 150 | 149 | } |
@@ -12,4 +12,4 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\Session; |
| 14 | 14 | |
| 15 | -class SessionHandlerException extends \Exception{} |
|
| 15 | +class SessionHandlerException extends \Exception {} |
|
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** |
| 17 | 17 | * Class FileSessionHandler |
| 18 | 18 | */ |
| 19 | -class FileSessionHandler extends SessionHandlerAbstract{ |
|
| 19 | +class FileSessionHandler extends SessionHandlerAbstract { |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * @var \chillerlan\Filereader\Drivers\FSDriverInterface |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param \chillerlan\Filereader\Drivers\FSDriverInterface $FSdriver |
| 30 | 30 | * @param \chillerlan\Session\SessionHandlerOptions $options |
| 31 | 31 | */ |
| 32 | - public function __construct(FSDriverInterface $FSdriver, SessionHandlerOptions $options = null){ |
|
| 32 | + public function __construct(FSDriverInterface $FSdriver, SessionHandlerOptions $options = null) { |
|
| 33 | 33 | parent::__construct($options); |
| 34 | 34 | |
| 35 | 35 | // use the internal DiskDriver if no other filereader was given |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function destroy($session_id):bool{ |
| 67 | 67 | $file = $this->options->save_path.$this->options->filename_prefix.$session_id; |
| 68 | 68 | |
| 69 | - if($this->filereader->fileExists($file)) { |
|
| 69 | + if ($this->filereader->fileExists($file)) { |
|
| 70 | 70 | $this->filereader->deleteFile($file); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | public function gc($maxlifetime):bool{ |
| 93 | 93 | $files = $this->filereader->findFiles($this->options->save_path.$this->options->filename_prefix.'*'); |
| 94 | 94 | |
| 95 | - if(is_array($files)){ |
|
| 95 | + if (is_array($files)) { |
|
| 96 | 96 | |
| 97 | - foreach($files as $file){ |
|
| 97 | + foreach ($files as $file) { |
|
| 98 | 98 | |
| 99 | - if($this->filereader->fileModifyTime($file) + $maxlifetime < time() && $this->filereader->fileExists($file)){ |
|
| 99 | + if ($this->filereader->fileModifyTime($file) + $maxlifetime < time() && $this->filereader->fileExists($file)) { |
|
| 100 | 100 | $this->filereader->deleteFile($file); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function open($save_path, $name):bool{ |
| 125 | 125 | |
| 126 | - if(!$this->filereader->isWritable($save_path)){ |
|
| 126 | + if (!$this->filereader->isWritable($save_path)) { |
|
| 127 | 127 | return false; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\Session; |
| 14 | 14 | |
| 15 | -interface SessionInterface{ |
|
| 15 | +interface SessionInterface { |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @return void |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | * @property string $use_encryption |
| 27 | 27 | * @property string $cryptoKey |
| 28 | 28 | */ |
| 29 | -class SessionHandlerOptions implements ContainerInterface{ |
|
| 29 | +class SessionHandlerOptions implements ContainerInterface { |
|
| 30 | 30 | use Container; |
| 31 | 31 | |
| 32 | 32 | protected $filename_prefix = 'SESSION_'; |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | use chillerlan\Database\Connection; |
| 16 | 16 | |
| 17 | -class DBSessionHandler extends SessionHandlerAbstract{ |
|
| 17 | +class DBSessionHandler extends SessionHandlerAbstract { |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @var \chillerlan\Database\Connection |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @param \chillerlan\Session\SessionHandlerOptions $options |
| 28 | 28 | * @param \chillerlan\Database\Connection $db |
| 29 | 29 | */ |
| 30 | - public function __construct(SessionHandlerOptions $options = null, Connection $db){ |
|
| 30 | + public function __construct(SessionHandlerOptions $options = null, Connection $db) { |
|
| 31 | 31 | parent::__construct($options); |
| 32 | 32 | |
| 33 | 33 | $this->db = $db; |
@@ -138,15 +138,15 @@ discard block |
||
| 138 | 138 | ->where('id', $session_id) |
| 139 | 139 | ->execute(); |
| 140 | 140 | |
| 141 | - try{ |
|
| 141 | + try { |
|
| 142 | 142 | |
| 143 | - if(!$q || !isset($q[0])){ |
|
| 143 | + if (!$q || !isset($q[0])) { |
|
| 144 | 144 | return ''; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return $this->decrypt($q[0]->data); |
| 148 | 148 | } |
| 149 | - catch(\Exception $e){ |
|
| 149 | + catch (\Exception $e) { |
|
| 150 | 150 | throw new SessionHandlerException($e->getMessage()); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -145,8 +145,7 @@ |
||
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return $this->decrypt($q[0]->data); |
| 148 | - } |
|
| 149 | - catch(\Exception $e){ |
|
| 148 | + } catch(\Exception $e){ |
|
| 150 | 149 | throw new SessionHandlerException($e->getMessage()); |
| 151 | 150 | } |
| 152 | 151 | |