diff --git a/deptrac.yaml b/deptrac.yaml index 8d43af6117ae..8d4728966523 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -155,6 +155,8 @@ parameters: API: - Format - HTTP + Cache: + - I18n Controller: - HTTP - Validation diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index babb7c037be1..05868272b731 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\Cache\Exceptions\CacheException; +use CodeIgniter\I18n\Time; use Config\Cache; use Throwable; @@ -91,7 +92,7 @@ public function save(string $key, $value, int $ttl = 60) $key = static::validateKey($key, $this->prefix); $contents = [ - 'time' => time(), + 'time' => Time::now()->getTimestamp(), 'ttl' => $ttl, 'data' => $value, ]; diff --git a/system/Cache/Handlers/MemcachedHandler.php b/system/Cache/Handlers/MemcachedHandler.php index 6b6f60e0a6b7..f7d5ec8bcd1a 100644 --- a/system/Cache/Handlers/MemcachedHandler.php +++ b/system/Cache/Handlers/MemcachedHandler.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\Exceptions\CriticalError; +use CodeIgniter\I18n\Time; use Config\Cache; use Exception; use Memcache; @@ -155,7 +156,7 @@ public function save(string $key, $value, int $ttl = 60) if (! $this->config['raw']) { $value = [ $value, - time(), + Time::now()->getTimestamp(), $ttl, ]; } diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index 87ab4e333dca..cf44f634e86b 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\Exceptions\CriticalError; +use CodeIgniter\I18n\Time; use Config\Cache; use Exception; use Predis\Client; @@ -128,7 +129,7 @@ public function save(string $key, $value, int $ttl = 60) } if ($ttl) { - $this->redis->expireat($key, time() + $ttl); + $this->redis->expireat($key, Time::now()->getTimestamp() + $ttl); } return true; @@ -204,11 +205,11 @@ public function getMetaData(string $key) $data = array_combine(['__ci_value'], $this->redis->hmget($key, ['__ci_value'])); if (isset($data['__ci_value']) && $data['__ci_value'] !== false) { - $time = time(); + $time = Time::now()->getTimestamp(); $ttl = $this->redis->ttl($key); return [ - 'expire' => $ttl > 0 ? time() + $ttl : null, + 'expire' => $ttl > 0 ? $time + $ttl : null, 'mtime' => $time, 'data' => $data['__ci_value'], ]; diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index b84c0115b1f8..8b3af5856319 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\Exceptions\CriticalError; +use CodeIgniter\I18n\Time; use Config\Cache; use Redis; use RedisException; @@ -154,7 +155,7 @@ public function save(string $key, $value, int $ttl = 60) } if ($ttl) { - $this->redis->expireAt($key, time() + $ttl); + $this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl); } return true; @@ -236,11 +237,11 @@ public function getMetaData(string $key) $value = $this->get($key); if ($value !== null) { - $time = time(); + $time = Time::now()->getTimestamp(); $ttl = $this->redis->ttl($key); return [ - 'expire' => $ttl > 0 ? time() + $ttl : null, + 'expire' => $ttl > 0 ? $time + $ttl : null, 'mtime' => $time, 'data' => $value, ]; diff --git a/system/Cache/Handlers/WincacheHandler.php b/system/Cache/Handlers/WincacheHandler.php index b13ee30c3ff6..e422dc1fad00 100644 --- a/system/Cache/Handlers/WincacheHandler.php +++ b/system/Cache/Handlers/WincacheHandler.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Cache\Handlers; +use CodeIgniter\I18n\Time; use Config\Cache; use Exception; @@ -124,7 +125,7 @@ public function getMetaData(string $key) $hitcount = $stored['ucache_entries'][1]['hitcount']; return [ - 'expire' => $ttl > 0 ? time() + $ttl : null, + 'expire' => $ttl > 0 ? Time::now()->getTimestamp() + $ttl : null, 'hitcount' => $hitcount, 'age' => $age, 'ttl' => $ttl, diff --git a/tests/system/Cache/Handlers/AbstractHandlerTest.php b/tests/system/Cache/Handlers/AbstractHandlerTest.php index 7ff02a729b49..75e45218e215 100644 --- a/tests/system/Cache/Handlers/AbstractHandlerTest.php +++ b/tests/system/Cache/Handlers/AbstractHandlerTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Cache\Handlers; +use CodeIgniter\I18n\Time; use CodeIgniter\Test\CIUnitTestCase; /** @@ -31,7 +32,7 @@ public function testGetMetaDataMiss() public function testGetMetaData() { - $time = time(); + $time = Time::now()->getTimestamp(); $this->handler->save(self::$key1, 'value'); $actual = $this->handler->getMetaData(self::$key1); diff --git a/tests/system/Cache/Handlers/FileHandlerTest.php b/tests/system/Cache/Handlers/FileHandlerTest.php index abba309ff516..dde4ca86e13d 100644 --- a/tests/system/Cache/Handlers/FileHandlerTest.php +++ b/tests/system/Cache/Handlers/FileHandlerTest.php @@ -13,6 +13,7 @@ use CodeIgniter\Cache\Exceptions\CacheException; use CodeIgniter\CLI\CLI; +use CodeIgniter\I18n\Time; use Config\Cache; /** @@ -156,7 +157,7 @@ public function testSavePermanent() $metaData = $this->handler->getMetaData(self::$key1); $this->assertNull($metaData['expire']); - $this->assertLessThanOrEqual(1, $metaData['mtime'] - time()); + $this->assertLessThanOrEqual(1, $metaData['mtime'] - Time::now()->getTimestamp()); $this->assertSame('value', $metaData['data']); $this->assertTrue($this->handler->delete(self::$key1)); diff --git a/tests/system/Cache/Handlers/MemcachedHandlerTest.php b/tests/system/Cache/Handlers/MemcachedHandlerTest.php index f6e2e45309c9..24465af9e7de 100644 --- a/tests/system/Cache/Handlers/MemcachedHandlerTest.php +++ b/tests/system/Cache/Handlers/MemcachedHandlerTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\CLI\CLI; +use CodeIgniter\I18n\Time; use Config\Cache; use Exception; @@ -105,7 +106,7 @@ public function testSavePermanent() $metaData = $this->handler->getMetaData(self::$key1); $this->assertNull($metaData['expire']); - $this->assertLessThanOrEqual(1, $metaData['mtime'] - time()); + $this->assertLessThanOrEqual(1, $metaData['mtime'] - Time::now()->getTimestamp()); $this->assertSame('value', $metaData['data']); $this->assertTrue($this->handler->delete(self::$key1)); diff --git a/tests/system/Cache/Handlers/PredisHandlerTest.php b/tests/system/Cache/Handlers/PredisHandlerTest.php index 60ed0a0e0c07..17a43e36263f 100644 --- a/tests/system/Cache/Handlers/PredisHandlerTest.php +++ b/tests/system/Cache/Handlers/PredisHandlerTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\CLI\CLI; +use CodeIgniter\I18n\Time; use Config\Cache; /** @@ -108,7 +109,7 @@ public function testSavePermanent() $metaData = $this->handler->getMetaData(self::$key1); $this->assertNull($metaData['expire']); - $this->assertLessThanOrEqual(1, $metaData['mtime'] - time()); + $this->assertLessThanOrEqual(1, $metaData['mtime'] - Time::now()->getTimestamp()); $this->assertSame('value', $metaData['data']); $this->assertTrue($this->handler->delete(self::$key1)); diff --git a/tests/system/Cache/Handlers/RedisHandlerTest.php b/tests/system/Cache/Handlers/RedisHandlerTest.php index 2c79be076eca..a31561336873 100644 --- a/tests/system/Cache/Handlers/RedisHandlerTest.php +++ b/tests/system/Cache/Handlers/RedisHandlerTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\CLI\CLI; +use CodeIgniter\I18n\Time; use Config\Cache; /** @@ -112,7 +113,7 @@ public function testSavePermanent() $metaData = $this->handler->getMetaData(self::$key1); $this->assertNull($metaData['expire']); - $this->assertLessThanOrEqual(1, $metaData['mtime'] - time()); + $this->assertLessThanOrEqual(1, $metaData['mtime'] - Time::now()->getTimestamp()); $this->assertSame('value', $metaData['data']); $this->assertTrue($this->handler->delete(self::$key1));