From b1935a4f064e1cd9f0ea01d65be9d20efddf5c31 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Sun, 13 Nov 2022 16:23:31 +0800 Subject: [PATCH 1/2] refactor: replace time() with Time in Session.php --- system/Session/Session.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/system/Session/Session.php b/system/Session/Session.php index fa44b8267e7b..d45a7b75fc74 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -13,6 +13,7 @@ use CodeIgniter\Cookie\Cookie; use CodeIgniter\HTTP\Response; +use CodeIgniter\I18n\Time; use Config\App; use Config\Cookie as CookieConfig; use Config\Services; @@ -182,7 +183,7 @@ public function __construct(SessionHandlerInterface $driver, App $config) $cookie = config('Cookie'); $this->cookie = (new Cookie($this->sessionCookieName, '', [ - 'expires' => $this->sessionExpiration === 0 ? 0 : time() + $this->sessionExpiration, + 'expires' => $this->sessionExpiration === 0 ? 0 : Time::now()->getTimestamp() + $this->sessionExpiration, 'path' => $cookie->path ?? $config->cookiePath, 'domain' => $cookie->domain ?? $config->cookieDomain, 'secure' => $cookie->secure ?? $config->cookieSecure, @@ -238,8 +239,8 @@ public function start() && ($regenerateTime = $this->sessionTimeToUpdate) > 0 ) { if (! isset($_SESSION['__ci_last_regenerate'])) { - $_SESSION['__ci_last_regenerate'] = time(); - } elseif ($_SESSION['__ci_last_regenerate'] < (time() - $regenerateTime)) { + $_SESSION['__ci_last_regenerate'] = Time::now()->getTimestamp(); + } elseif ($_SESSION['__ci_last_regenerate'] < (Time::now()->getTimestamp() - $regenerateTime)) { $this->regenerate((bool) $this->sessionRegenerateDestroy); } } @@ -379,7 +380,7 @@ protected function initVars() return; } - $currentTime = time(); + $currentTime = Time::now()->getTimestamp(); foreach ($_SESSION['__ci_vars'] as $key => &$value) { if ($value === 'new') { @@ -403,7 +404,7 @@ protected function initVars() */ public function regenerate(bool $destroy = false) { - $_SESSION['__ci_last_regenerate'] = time(); + $_SESSION['__ci_last_regenerate'] = Time::now()->getTimestamp(); session_regenerate_id($destroy); $this->removeOldSessionCookie(); @@ -804,7 +805,7 @@ public function removeTempdata(string $key) */ public function markAsTempdata($key, int $ttl = 300): bool { - $ttl += time(); + $ttl += Time::now()->getTimestamp(); if (is_array($key)) { $temp = []; @@ -815,9 +816,9 @@ public function markAsTempdata($key, int $ttl = 300): bool $k = $v; $v = $ttl; } elseif (is_string($v)) { - $v = time() + $ttl; + $v = Time::now()->getTimestamp() + $ttl; } else { - $v += time(); + $v += Time::now()->getTimestamp(); } if (! array_key_exists($k, $_SESSION)) { @@ -919,7 +920,7 @@ protected function startSession() */ protected function setCookie() { - $expiration = $this->sessionExpiration === 0 ? 0 : time() + $this->sessionExpiration; + $expiration = $this->sessionExpiration === 0 ? 0 : Time::now()->getTimestamp() + $this->sessionExpiration; $this->cookie = $this->cookie->withValue(session_id())->withExpires($expiration); /** @var Response $response */ From c419e6a62d3d3423a45182de2ab89fcd2534e8ce Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Sun, 13 Nov 2022 21:00:44 +0800 Subject: [PATCH 2/2] Add the I18n dependency into session class. --- deptrac.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/deptrac.yaml b/deptrac.yaml index 8d43af6117ae..ddcaa43d9dba 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -201,6 +201,7 @@ parameters: - Cookie - HTTP - Database + - I18n Throttle: - Cache Validation: