Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace time() with Time into whole Session class. #6857

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Session\Handlers;

use CodeIgniter\I18n\Time;
use CodeIgniter\Session\Exceptions\SessionException;
use Config\App as AppConfig;
use ReturnTypeWillChange;
Expand Down Expand Up @@ -276,7 +277,7 @@ public function gc($max_lifetime)
return false;
}

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

$pattern = $this->matchIP === true ? '[0-9a-f]{32}' : '';

Expand Down
7 changes: 4 additions & 3 deletions system/Session/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Session\Handlers;

use CodeIgniter\I18n\Time;
use CodeIgniter\Session\Exceptions\SessionException;
use Config\App as AppConfig;
use Memcached;
Expand Down Expand Up @@ -167,7 +168,7 @@ public function write($id, $data): bool
}

if (isset($this->lockKey)) {
$this->memcached->replace($this->lockKey, time(), 300);
$this->memcached->replace($this->lockKey, Time::now()->getTimestamp(), 300);

if ($this->fingerprint !== ($fingerprint = md5($data))) {
if ($this->memcached->set($this->keyPrefix . $id, $data, $this->sessionExpiration)) {
Expand Down Expand Up @@ -245,7 +246,7 @@ public function gc($max_lifetime)
protected function lockSession(string $sessionID): bool
{
if (isset($this->lockKey)) {
return $this->memcached->replace($this->lockKey, time(), 300);
return $this->memcached->replace($this->lockKey, Time::now()->getTimestamp(), 300);
}

$lockKey = $this->keyPrefix . $sessionID . ':lock';
Expand All @@ -258,7 +259,7 @@ protected function lockSession(string $sessionID): bool
continue;
}

if (! $this->memcached->set($lockKey, time(), 300)) {
if (! $this->memcached->set($lockKey, Time::now()->getTimestamp(), 300)) {
$this->logger->error('Session: Error while trying to obtain lock for ' . $this->keyPrefix . $sessionID);

return false;
Expand Down
3 changes: 2 additions & 1 deletion system/Session/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Session\Handlers;

use CodeIgniter\I18n\Time;
use CodeIgniter\Session\Exceptions\SessionException;
use Config\App as AppConfig;
use Redis;
Expand Down Expand Up @@ -293,7 +294,7 @@ protected function lockSession(string $sessionID): bool
continue;
}

if (! $this->redis->setex($lockKey, 300, (string) time())) {
if (! $this->redis->setex($lockKey, 300, (string) Time::now()->getTimestamp())) {
$this->logger->error('Session: Error while trying to obtain lock for ' . $this->keyPrefix . $sessionID);

return false;
Expand Down