Skip to content

Commit 4b1f73c

Browse files
committed
refactor: make time() to class Time
1 parent a9859e8 commit 4b1f73c

5 files changed

Lines changed: 14 additions & 9 deletions

File tree

system/Cache/Handlers/FileHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Cache\Handlers;
1313

1414
use CodeIgniter\Cache\Exceptions\CacheException;
15+
use CodeIgniter\I18n\Time;
1516
use Config\Cache;
1617
use Throwable;
1718

@@ -91,7 +92,7 @@ public function save(string $key, $value, int $ttl = 60)
9192
$key = static::validateKey($key, $this->prefix);
9293

9394
$contents = [
94-
'time' => time(),
95+
'time' => Time::now()->getTimestamp(),
9596
'ttl' => $ttl,
9697
'data' => $value,
9798
];

system/Cache/Handlers/MemcachedHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Cache\Handlers;
1313

1414
use CodeIgniter\Exceptions\CriticalError;
15+
use CodeIgniter\I18n\Time;
1516
use Config\Cache;
1617
use Exception;
1718
use Memcache;
@@ -155,7 +156,7 @@ public function save(string $key, $value, int $ttl = 60)
155156
if (! $this->config['raw']) {
156157
$value = [
157158
$value,
158-
time(),
159+
Time::now()->getTimestamp(),
159160
$ttl,
160161
];
161162
}

system/Cache/Handlers/PredisHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Cache\Handlers;
1313

1414
use CodeIgniter\Exceptions\CriticalError;
15+
use CodeIgniter\I18n\Time;
1516
use Config\Cache;
1617
use Exception;
1718
use Predis\Client;
@@ -128,7 +129,7 @@ public function save(string $key, $value, int $ttl = 60)
128129
}
129130

130131
if ($ttl) {
131-
$this->redis->expireat($key, time() + $ttl);
132+
$this->redis->expireat($key, Time::now()->getTimestamp() + $ttl);
132133
}
133134

134135
return true;
@@ -204,11 +205,11 @@ public function getMetaData(string $key)
204205
$data = array_combine(['__ci_value'], $this->redis->hmget($key, ['__ci_value']));
205206

206207
if (isset($data['__ci_value']) && $data['__ci_value'] !== false) {
207-
$time = time();
208+
$time = Time::now()->getTimestamp();
208209
$ttl = $this->redis->ttl($key);
209210

210211
return [
211-
'expire' => $ttl > 0 ? time() + $ttl : null,
212+
'expire' => $ttl > 0 ? $time + $ttl : null,
212213
'mtime' => $time,
213214
'data' => $data['__ci_value'],
214215
];

system/Cache/Handlers/RedisHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Cache\Handlers;
1313

1414
use CodeIgniter\Exceptions\CriticalError;
15+
use CodeIgniter\I18n\Time;
1516
use Config\Cache;
1617
use Redis;
1718
use RedisException;
@@ -154,7 +155,7 @@ public function save(string $key, $value, int $ttl = 60)
154155
}
155156

156157
if ($ttl) {
157-
$this->redis->expireAt($key, time() + $ttl);
158+
$this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl);
158159
}
159160

160161
return true;
@@ -236,11 +237,11 @@ public function getMetaData(string $key)
236237
$value = $this->get($key);
237238

238239
if ($value !== null) {
239-
$time = time();
240+
$time = Time::now()->getTimestamp();
240241
$ttl = $this->redis->ttl($key);
241242

242243
return [
243-
'expire' => $ttl > 0 ? time() + $ttl : null,
244+
'expire' => $ttl > 0 ? $time + $ttl : null,
244245
'mtime' => $time,
245246
'data' => $value,
246247
];

system/Cache/Handlers/WincacheHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Cache\Handlers;
1313

14+
use CodeIgniter\I18n\Time;
1415
use Config\Cache;
1516
use Exception;
1617

@@ -124,7 +125,7 @@ public function getMetaData(string $key)
124125
$hitcount = $stored['ucache_entries'][1]['hitcount'];
125126

126127
return [
127-
'expire' => $ttl > 0 ? time() + $ttl : null,
128+
'expire' => $ttl > 0 ? Time::now()->getTimestamp() + $ttl : null,
128129
'hitcount' => $hitcount,
129130
'age' => $age,
130131
'ttl' => $ttl,

0 commit comments

Comments
 (0)