From 75bc902bc3ae43a362de7832c75883ab93452944 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 16 Nov 2022 02:34:28 +0700 Subject: [PATCH] Fix cs and rollback numeric change for match -> switch Signed-off-by: Abdul Malik Ikhsan --- src/AbstractContainer.php | 4 ++-- src/Config/SessionConfig.php | 12 +++++++++++- src/SessionManager.php | 8 ++++++-- src/Validator/Id.php | 18 +++++++++++++----- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/AbstractContainer.php b/src/AbstractContainer.php index 2c6416c9..80b525fa 100644 --- a/src/AbstractContainer.php +++ b/src/AbstractContainer.php @@ -536,7 +536,7 @@ public function setExpirationSeconds($ttl, $vars = null) // Map item keys => timestamp $expires = array_flip($expires); - $expires = array_map(static fn(): int => $ts, $expires); + $expires = array_map(static fn() => $ts, $expires); // Create metadata array to merge in $data = ['EXPIRE_KEYS' => $expires]; @@ -583,7 +583,7 @@ public function setExpirationHops($hops, $vars = null) // Map item keys => timestamp $expires = array_flip($expires); - $expires = array_map(static fn(): array => ['hops' => $hops, 'ts' => $ts], $expires); + $expires = array_map(static fn() => ['hops' => $hops, 'ts' => $ts], $expires); // Create metadata array to merge in $data = ['EXPIRE_HOPS_KEYS' => $expires]; diff --git a/src/Config/SessionConfig.php b/src/Config/SessionConfig.php index c417ba9e..04e75362 100644 --- a/src/Config/SessionConfig.php +++ b/src/Config/SessionConfig.php @@ -202,10 +202,20 @@ public function setStorageOption($storageName, $storageValue) public function getStorageOption($storageOption) { return match ($storageOption) { + // No remote storage option; just return the current value 'remember_me_seconds' => $this->rememberMeSeconds, + 'url_rewriter_tags' => ini_get('url_rewriter.tags'), - 'use_cookies', 'use_only_cookies', 'use_trans_sid', 'cookie_httponly' => (bool) ini_get('session.' . $storageOption), + + // The following all need a transformation on the retrieved value; + // however they use the same key naming scheme + 'use_cookies', + 'use_only_cookies', + 'use_trans_sid', + 'cookie_httponly' => (bool) ini_get('session.' . $storageOption), + 'save_handler' => $this->saveHandler ?: $this->sessionModuleName(), + default => ini_get('session.' . $storageOption), }; } diff --git a/src/SessionManager.php b/src/SessionManager.php index 707e12d8..ef7d967a 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -443,8 +443,12 @@ public function expireSessionCookie() } setcookie( $this->getName(), // session name - '', - ['expires' => $_SERVER['REQUEST_TIME'] - 42000, 'path' => $config->getCookiePath(), 'domain' => $config->getCookieDomain(), 'secure' => (bool) $config->getCookieSecure(), 'httponly' => (bool) $config->getCookieHttpOnly()] + '', // value + $_SERVER['REQUEST_TIME'] - 42000, // TTL for cookie + $config->getCookiePath(), + $config->getCookieDomain(), + (bool) $config->getCookieSecure(), + (bool) $config->getCookieHttpOnly() ); } diff --git a/src/Validator/Id.php b/src/Validator/Id.php index eea5316d..71eace4b 100644 --- a/src/Validator/Id.php +++ b/src/Validator/Id.php @@ -58,11 +58,19 @@ public function isValid() // Get the session id bits per character INI setting, using 5 if unavailable $hashBitsPerChar = ini_get('session.sid_bits_per_character') ?: 5; - $pattern = match ($hashBitsPerChar) { - 4 => '#^[0-9a-f]*$#', - 6 => '#^[0-9a-zA-Z-,]*$#', - default => '#^[0-9a-v]*$#', - }; + switch ($hashBitsPerChar) { + case 4: + $pattern = '#^[0-9a-f]*$#'; + break; + case 6: + $pattern = '#^[0-9a-zA-Z-,]*$#'; + break; + case 5: + // intentionally fall-through + default: + $pattern = '#^[0-9a-v]*$#'; + break; + } return (bool) preg_match($pattern, $id); }