Skip to content

Commit

Permalink
Merge pull request #6847 from ping-yee/refactor-replace-time-in-session
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner authored Nov 14, 2022
2 parents 9167ea9 + c419e6a commit 11bb96b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions deptrac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ parameters:
- Cookie
- HTTP
- Database
- I18n
Throttle:
- Cache
Validation:
Expand Down
19 changes: 10 additions & 9 deletions system/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -379,7 +380,7 @@ protected function initVars()
return;
}

$currentTime = time();
$currentTime = Time::now()->getTimestamp();

foreach ($_SESSION['__ci_vars'] as $key => &$value) {
if ($value === 'new') {
Expand All @@ -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();
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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)) {
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 11bb96b

Please sign in to comment.