Skip to content

Commit

Permalink
Fix cs and rollback numeric change for match -> switch
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik committed Nov 15, 2022
1 parent 4d11297 commit 75bc902
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
12 changes: 11 additions & 1 deletion src/Config/SessionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
Expand Down
8 changes: 6 additions & 2 deletions src/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
18 changes: 13 additions & 5 deletions src/Validator/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 75bc902

Please sign in to comment.