@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class RedisOptionBuilderFeatureTest extends TestCase |
| 6 | 6 | { |
| 7 | - public function test_it_builds_redis_options() |
|
| 8 | - { |
|
| 7 | + public function test_it_builds_redis_options() |
|
| 8 | + { |
|
| 9 | 9 | $options = OptionBuilder::forRedis() |
| 10 | - ->setNamespace('app:') |
|
| 11 | - ->expirationTime('2 hours') |
|
| 12 | - ->flushAfter('1 day') |
|
| 13 | - ->build(); |
|
| 10 | + ->setNamespace('app:') |
|
| 11 | + ->expirationTime('2 hours') |
|
| 12 | + ->flushAfter('1 day') |
|
| 13 | + ->build(); |
|
| 14 | 14 | |
| 15 | 15 | $this->assertArrayHasKey('namespace', $options); |
| 16 | 16 | $this->assertArrayHasKey('expirationTime', $options); |
@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | $this->assertSame('app:', $options['namespace']); |
| 20 | 20 | $this->assertSame('2 hours', $options['expirationTime']); |
| 21 | 21 | $this->assertSame('1 day', $options['flushAfter']); |
| 22 | - } |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function test_it_allows_timebuilder_for_redis() |
|
| 25 | - { |
|
| 24 | + public function test_it_allows_timebuilder_for_redis() |
|
| 25 | + { |
|
| 26 | 26 | $options = OptionBuilder::forRedis() |
| 27 | - ->expirationTime()->minute(30) |
|
| 28 | - ->flushAfter()->day(2) |
|
| 29 | - ->build(); |
|
| 27 | + ->expirationTime()->minute(30) |
|
| 28 | + ->flushAfter()->day(2) |
|
| 29 | + ->build(); |
|
| 30 | 30 | |
| 31 | 31 | $this->assertSame('30 minutes', $options['expirationTime']); |
| 32 | 32 | $this->assertSame('2 days', $options['flushAfter']); |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class DatabaseOptionBuilderFeatureTest extends TestCase |
| 6 | 6 | { |
| 7 | - public function test_it_builds_database_options() |
|
| 8 | - { |
|
| 7 | + public function test_it_builds_database_options() |
|
| 8 | + { |
|
| 9 | 9 | $options = OptionBuilder::forDatabase() |
| 10 | - ->table('cache_items') |
|
| 11 | - ->expirationTime('12 hours') |
|
| 12 | - ->flushAfter('7 days') |
|
| 13 | - ->build(); |
|
| 10 | + ->table('cache_items') |
|
| 11 | + ->expirationTime('12 hours') |
|
| 12 | + ->flushAfter('7 days') |
|
| 13 | + ->build(); |
|
| 14 | 14 | |
| 15 | 15 | $this->assertArrayHasKey('table', $options); |
| 16 | 16 | $this->assertArrayHasKey('expirationTime', $options); |
@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | $this->assertSame('cache_items', $options['table']); |
| 20 | 20 | $this->assertSame('12 hours', $options['expirationTime']); |
| 21 | 21 | $this->assertSame('7 days', $options['flushAfter']); |
| 22 | - } |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function test_it_allows_timebuilder_for_database() |
|
| 25 | - { |
|
| 24 | + public function test_it_allows_timebuilder_for_database() |
|
| 25 | + { |
|
| 26 | 26 | $options = OptionBuilder::forDatabase() |
| 27 | - ->expirationTime()->hour(6) |
|
| 28 | - ->flushAfter()->week(1) |
|
| 29 | - ->build(); |
|
| 27 | + ->expirationTime()->hour(6) |
|
| 28 | + ->flushAfter()->week(1) |
|
| 29 | + ->build(); |
|
| 30 | 30 | |
| 31 | 31 | $this->assertSame('6 hours', $options['expirationTime']); |
| 32 | 32 | $this->assertSame('1 weeks', $options['flushAfter']); |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -8,38 +8,38 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class RedisOptionBuilderStoreTest extends TestCase |
| 10 | 10 | { |
| 11 | - private ?PredisClient $client = null; |
|
| 11 | + private ?PredisClient $client = null; |
|
| 12 | 12 | |
| 13 | - protected function setUp(): void |
|
| 14 | - { |
|
| 13 | + protected function setUp(): void |
|
| 14 | + { |
|
| 15 | 15 | // Try to connect to Redis; skip if not available |
| 16 | 16 | try { |
| 17 | - PredisAutoloader::register(); |
|
| 18 | - $this->client = new PredisClient([ |
|
| 17 | + PredisAutoloader::register(); |
|
| 18 | + $this->client = new PredisClient([ |
|
| 19 | 19 | 'scheme' => 'tcp', |
| 20 | 20 | 'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'] ?? '127.0.0.1', |
| 21 | 21 | 'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'] ?? 6379, |
| 22 | - ]); |
|
| 23 | - $this->client->connect(); |
|
| 24 | - // simple call to verify |
|
| 25 | - $this->client->ping(); |
|
| 22 | + ]); |
|
| 23 | + $this->client->connect(); |
|
| 24 | + // simple call to verify |
|
| 25 | + $this->client->ping(); |
|
| 26 | 26 | } catch (\Throwable $e) { |
| 27 | - $this->markTestSkipped('Redis not available: ' . $e->getMessage()); |
|
| 27 | + $this->markTestSkipped('Redis not available: ' . $e->getMessage()); |
|
| 28 | + } |
|
| 28 | 29 | } |
| 29 | - } |
|
| 30 | 30 | |
| 31 | - protected function tearDown(): void |
|
| 32 | - { |
|
| 31 | + protected function tearDown(): void |
|
| 32 | + { |
|
| 33 | 33 | if ($this->client) { |
| 34 | - $this->client->disconnect(); |
|
| 34 | + $this->client->disconnect(); |
|
| 35 | + } |
|
| 35 | 36 | } |
| 36 | - } |
|
| 37 | 37 | |
| 38 | - public function test_redis_store_uses_namespace_from_option_builder() |
|
| 39 | - { |
|
| 38 | + public function test_redis_store_uses_namespace_from_option_builder() |
|
| 39 | + { |
|
| 40 | 40 | $options = OptionBuilder::forRedis() |
| 41 | - ->setNamespace('app:') |
|
| 42 | - ->build(); |
|
| 41 | + ->setNamespace('app:') |
|
| 42 | + ->build(); |
|
| 43 | 43 | |
| 44 | 44 | $cache = new Cacheer($options); |
| 45 | 45 | $cache->setDriver()->useRedisDriver(); |
@@ -55,6 +55,6 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | $read = $cache->getCache($key); |
| 57 | 57 | $this->assertEquals($data, $read); |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | } |
| 60 | 60 | |
@@ -9,37 +9,37 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | class RedisOptionBuilderTTLAndFlushTest extends TestCase |
| 11 | 11 | { |
| 12 | - private ?PredisClient $client = null; |
|
| 12 | + private ?PredisClient $client = null; |
|
| 13 | 13 | |
| 14 | - protected function setUp(): void |
|
| 15 | - { |
|
| 14 | + protected function setUp(): void |
|
| 15 | + { |
|
| 16 | 16 | try { |
| 17 | - PredisAutoloader::register(); |
|
| 18 | - $this->client = new PredisClient([ |
|
| 17 | + PredisAutoloader::register(); |
|
| 18 | + $this->client = new PredisClient([ |
|
| 19 | 19 | 'scheme' => 'tcp', |
| 20 | 20 | 'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'] ?? '127.0.0.1', |
| 21 | 21 | 'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'] ?? 6379, |
| 22 | - ]); |
|
| 23 | - $this->client->connect(); |
|
| 24 | - $this->client->ping(); |
|
| 22 | + ]); |
|
| 23 | + $this->client->connect(); |
|
| 24 | + $this->client->ping(); |
|
| 25 | 25 | } catch (\Throwable $e) { |
| 26 | - $this->markTestSkipped('Redis not available: ' . $e->getMessage()); |
|
| 26 | + $this->markTestSkipped('Redis not available: ' . $e->getMessage()); |
|
| 27 | + } |
|
| 27 | 28 | } |
| 28 | - } |
|
| 29 | 29 | |
| 30 | - protected function tearDown(): void |
|
| 31 | - { |
|
| 30 | + protected function tearDown(): void |
|
| 31 | + { |
|
| 32 | 32 | if ($this->client) { |
| 33 | - $this->client->disconnect(); |
|
| 33 | + $this->client->disconnect(); |
|
| 34 | + } |
|
| 34 | 35 | } |
| 35 | - } |
|
| 36 | 36 | |
| 37 | - public function test_expiration_time_from_options_sets_default_ttl() |
|
| 38 | - { |
|
| 37 | + public function test_expiration_time_from_options_sets_default_ttl() |
|
| 38 | + { |
|
| 39 | 39 | $options = OptionBuilder::forRedis() |
| 40 | - ->setNamespace('app:') |
|
| 41 | - ->expirationTime('1 seconds') |
|
| 42 | - ->build(); |
|
| 40 | + ->setNamespace('app:') |
|
| 41 | + ->expirationTime('1 seconds') |
|
| 42 | + ->build(); |
|
| 43 | 43 | |
| 44 | 44 | $cache = new Cacheer($options); |
| 45 | 45 | $cache->setDriver()->useRedisDriver(); |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | sleep(2); |
| 52 | 52 | $this->assertNull($cache->getCache($key)); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function test_flush_after_from_options_triggers_auto_flush() |
|
| 56 | - { |
|
| 55 | + public function test_flush_after_from_options_triggers_auto_flush() |
|
| 56 | + { |
|
| 57 | 57 | $options = OptionBuilder::forRedis() |
| 58 | - ->setNamespace('app:') |
|
| 59 | - ->flushAfter('1 seconds') |
|
| 60 | - ->build(); |
|
| 58 | + ->setNamespace('app:') |
|
| 59 | + ->flushAfter('1 seconds') |
|
| 60 | + ->build(); |
|
| 61 | 61 | |
| 62 | 62 | $flushFile = FlushHelper::pathFor('redis', 'app:'); |
| 63 | 63 | file_put_contents($flushFile, (string) (time() - 3600)); |
@@ -71,5 +71,5 @@ discard block |
||
| 71 | 71 | $cache = new Cacheer($options); |
| 72 | 72 | $cache->setDriver()->useRedisDriver(); |
| 73 | 73 | $this->assertFalse((bool)$this->client->exists('app:to_be_flushed')); |
| 74 | - } |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -7,11 +7,11 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class DatabaseOptionBuilderStoreTest extends TestCase |
| 9 | 9 | { |
| 10 | - private ?PDO $pdo = null; |
|
| 11 | - private string $table = 'cache_items'; |
|
| 10 | + private ?PDO $pdo = null; |
|
| 11 | + private string $table = 'cache_items'; |
|
| 12 | 12 | |
| 13 | - protected function setUp(): void |
|
| 14 | - { |
|
| 13 | + protected function setUp(): void |
|
| 14 | + { |
|
| 15 | 15 | // Ensure SQLite connection and create a custom table for this test |
| 16 | 16 | $this->pdo = Connect::getInstance(); |
| 17 | 17 | |
@@ -30,20 +30,20 @@ discard block |
||
| 30 | 30 | CREATE INDEX IF NOT EXISTS idx_{$this->table}_expirationTime ON {$this->table} (expirationTime); |
| 31 | 31 | CREATE INDEX IF NOT EXISTS idx_{$this->table}_key_namespace ON {$this->table} (cacheKey, cacheNamespace); |
| 32 | 32 | "); |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - protected function tearDown(): void |
|
| 36 | - { |
|
| 35 | + protected function tearDown(): void |
|
| 36 | + { |
|
| 37 | 37 | if ($this->pdo instanceof PDO) { |
| 38 | - $this->pdo->exec("DROP TABLE IF EXISTS {$this->table}"); |
|
| 38 | + $this->pdo->exec("DROP TABLE IF EXISTS {$this->table}"); |
|
| 39 | + } |
|
| 39 | 40 | } |
| 40 | - } |
|
| 41 | 41 | |
| 42 | - public function test_database_store_uses_custom_table_from_option_builder() |
|
| 43 | - { |
|
| 42 | + public function test_database_store_uses_custom_table_from_option_builder() |
|
| 43 | + { |
|
| 44 | 44 | $options = OptionBuilder::forDatabase() |
| 45 | - ->table($this->table) |
|
| 46 | - ->build(); |
|
| 45 | + ->table($this->table) |
|
| 46 | + ->build(); |
|
| 47 | 47 | |
| 48 | 48 | $cache = new Cacheer($options); |
| 49 | 49 | $cache->setDriver()->useDatabaseDriver(); |
@@ -67,6 +67,6 @@ discard block |
||
| 67 | 67 | // And ensure Cacheer can read it back through the store |
| 68 | 68 | $read = $cache->getCache($key); |
| 69 | 69 | $this->assertEquals($data, $read); |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
@@ -7,10 +7,10 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class DatabaseOptionBuilderTTLAndFlushTest extends TestCase |
| 9 | 9 | { |
| 10 | - private string $table = 'cache_items_ttl_flush'; |
|
| 10 | + private string $table = 'cache_items_ttl_flush'; |
|
| 11 | 11 | |
| 12 | - protected function setUp(): void |
|
| 13 | - { |
|
| 12 | + protected function setUp(): void |
|
| 13 | + { |
|
| 14 | 14 | // Ensure the custom table exists (SQLite-compatible DDL) |
| 15 | 15 | $pdo = Silviooosilva\CacheerPhp\Core\Connect::getInstance(); |
| 16 | 16 | $pdo->exec("CREATE TABLE IF NOT EXISTS {$this->table} ( |
@@ -27,25 +27,25 @@ discard block |
||
| 27 | 27 | CREATE INDEX IF NOT EXISTS idx_{$this->table}_expirationTime ON {$this->table} (expirationTime); |
| 28 | 28 | CREATE INDEX IF NOT EXISTS idx_{$this->table}_key_namespace ON {$this->table} (cacheKey, cacheNamespace); |
| 29 | 29 | "); |
| 30 | - } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - protected function tearDown(): void |
|
| 33 | - { |
|
| 32 | + protected function tearDown(): void |
|
| 33 | + { |
|
| 34 | 34 | // clean up flush file |
| 35 | 35 | $path = FlushHelper::pathFor('db', $this->table); |
| 36 | 36 | if (file_exists($path)) { |
| 37 | - @unlink($path); |
|
| 37 | + @unlink($path); |
|
| 38 | 38 | } |
| 39 | 39 | $pdo = Silviooosilva\CacheerPhp\Core\Connect::getInstance(); |
| 40 | 40 | $pdo->exec("DROP TABLE IF EXISTS {$this->table}"); |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function test_expiration_time_from_options_sets_default_ttl() |
|
| 44 | - { |
|
| 43 | + public function test_expiration_time_from_options_sets_default_ttl() |
|
| 44 | + { |
|
| 45 | 45 | $options = OptionBuilder::forDatabase() |
| 46 | - ->table($this->table) |
|
| 47 | - ->expirationTime('-1 seconds') |
|
| 48 | - ->build(); |
|
| 46 | + ->table($this->table) |
|
| 47 | + ->expirationTime('-1 seconds') |
|
| 48 | + ->build(); |
|
| 49 | 49 | |
| 50 | 50 | $cache = new Cacheer($options); |
| 51 | 51 | $cache->setDriver()->useDatabaseDriver(); |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | $row = $stmt->fetch(PDO::FETCH_ASSOC); |
| 64 | 64 | $this->assertNotFalse($row); |
| 65 | 65 | $this->assertLessThanOrEqual(time(), strtotime($row['expirationTime'])); |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function test_flush_after_from_options_triggers_auto_flush() |
|
| 69 | - { |
|
| 68 | + public function test_flush_after_from_options_triggers_auto_flush() |
|
| 69 | + { |
|
| 70 | 70 | $options = OptionBuilder::forDatabase() |
| 71 | - ->table($this->table) |
|
| 72 | - ->flushAfter('1 seconds') |
|
| 73 | - ->build(); |
|
| 71 | + ->table($this->table) |
|
| 72 | + ->flushAfter('1 seconds') |
|
| 73 | + ->build(); |
|
| 74 | 74 | |
| 75 | 75 | // Pre-create an old last flush file to force a flush on init |
| 76 | 76 | $flushFile = FlushHelper::pathFor('db', $this->table); |
@@ -87,5 +87,5 @@ discard block |
||
| 87 | 87 | $cache->setDriver()->useDatabaseDriver(); |
| 88 | 88 | |
| 89 | 89 | $this->assertEmpty($cache->getAll()); |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * @var Cacheer |
|
| 24 | - */ |
|
| 23 | + * @var Cacheer |
|
| 24 | + */ |
|
| 25 | 25 | protected Cacheer $cacheer; |
| 26 | 26 | |
| 27 | 27 | /** @param string $logPath */ |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * Uses the database driver for caching. |
|
| 42 | - * |
|
| 43 | - * @return Cacheer |
|
| 44 | - */ |
|
| 41 | + * Uses the database driver for caching. |
|
| 42 | + * |
|
| 43 | + * @return Cacheer |
|
| 44 | + */ |
|
| 45 | 45 | public function useDatabaseDriver(): Cacheer |
| 46 | 46 | { |
| 47 | 47 | $this->cacheer->cacheStore = new DatabaseCacheStore($this->logPath, $this->cacheer->options); |
@@ -49,10 +49,10 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | - * Uses the file driver for caching. |
|
| 53 | - * |
|
| 54 | - * @return Cacheer |
|
| 55 | - */ |
|
| 52 | + * Uses the file driver for caching. |
|
| 53 | + * |
|
| 54 | + * @return Cacheer |
|
| 55 | + */ |
|
| 56 | 56 | public function useFileDriver(): Cacheer |
| 57 | 57 | { |
| 58 | 58 | $this->cacheer->options['loggerPath'] = $this->logPath; |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | - * Uses the Redis driver for caching. |
|
| 65 | - * |
|
| 66 | - * @return Cacheer |
|
| 67 | - */ |
|
| 64 | + * Uses the Redis driver for caching. |
|
| 65 | + * |
|
| 66 | + * @return Cacheer |
|
| 67 | + */ |
|
| 68 | 68 | public function useRedisDriver(): Cacheer |
| 69 | 69 | { |
| 70 | 70 | $this->cacheer->cacheStore = new RedisCacheStore($this->logPath, $this->cacheer->options); |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | - * Uses the array driver for caching. |
|
| 76 | - * |
|
| 77 | - * @return Cacheer |
|
| 78 | - */ |
|
| 75 | + * Uses the array driver for caching. |
|
| 76 | + * |
|
| 77 | + * @return Cacheer |
|
| 78 | + */ |
|
| 79 | 79 | public function useArrayDriver(): Cacheer |
| 80 | 80 | { |
| 81 | 81 | $this->cacheer->cacheStore = new ArrayCacheStore($this->logPath); |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | - * Uses the default driver for caching. |
|
| 87 | - * |
|
| 88 | - * @return Cacheer |
|
| 89 | - */ |
|
| 86 | + * Uses the default driver for caching. |
|
| 87 | + * |
|
| 88 | + * @return Cacheer |
|
| 89 | + */ |
|
| 90 | 90 | public function useDefaultDriver(): Cacheer |
| 91 | 91 | { |
| 92 | 92 | if (!isset($this->cacheer->options['cacheDir'])) { |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | - * Checks if the directory exists or creates it. |
|
| 107 | - * |
|
| 108 | - * @param mixed $dirName |
|
| 109 | - * @return bool |
|
| 110 | - */ |
|
| 106 | + * Checks if the directory exists or creates it. |
|
| 107 | + * |
|
| 108 | + * @param mixed $dirName |
|
| 109 | + * @return bool |
|
| 110 | + */ |
|
| 111 | 111 | private function isDir(mixed $dirName): bool |
| 112 | 112 | { |
| 113 | - if (is_dir($dirName)) { |
|
| 114 | - return true; |
|
| 115 | - } |
|
| 116 | - return mkdir($dirName, 0755, true); |
|
| 113 | + if (is_dir($dirName)) { |
|
| 114 | + return true; |
|
| 115 | + } |
|
| 116 | + return mkdir($dirName, 0755, true); |
|
| 117 | 117 | } |
| 118 | 118 | } |
@@ -14,33 +14,33 @@ |
||
| 14 | 14 | class OptionBuilder |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Creates a FileOptionBuilder instance for file-based cache options. |
|
| 19 | - * |
|
| 20 | - * @return FileOptionBuilder |
|
| 21 | - */ |
|
| 22 | - public static function forFile(): FileOptionBuilder |
|
| 23 | - { |
|
| 17 | + /** |
|
| 18 | + * Creates a FileOptionBuilder instance for file-based cache options. |
|
| 19 | + * |
|
| 20 | + * @return FileOptionBuilder |
|
| 21 | + */ |
|
| 22 | + public static function forFile(): FileOptionBuilder |
|
| 23 | + { |
|
| 24 | 24 | return new FileOptionBuilder(); |
| 25 | - } |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Creates a RedisOptionBuilder instance for Redis cache options. |
|
| 29 | - * |
|
| 30 | - * @return RedisOptionBuilder |
|
| 31 | - */ |
|
| 32 | - public static function forRedis(): RedisOptionBuilder |
|
| 33 | - { |
|
| 27 | + /** |
|
| 28 | + * Creates a RedisOptionBuilder instance for Redis cache options. |
|
| 29 | + * |
|
| 30 | + * @return RedisOptionBuilder |
|
| 31 | + */ |
|
| 32 | + public static function forRedis(): RedisOptionBuilder |
|
| 33 | + { |
|
| 34 | 34 | return new RedisOptionBuilder(); |
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Creates a DatabaseOptionBuilder instance for database cache options. |
|
| 39 | - * |
|
| 40 | - * @return DatabaseOptionBuilder |
|
| 41 | - */ |
|
| 42 | - public static function forDatabase(): DatabaseOptionBuilder |
|
| 43 | - { |
|
| 37 | + /** |
|
| 38 | + * Creates a DatabaseOptionBuilder instance for database cache options. |
|
| 39 | + * |
|
| 40 | + * @return DatabaseOptionBuilder |
|
| 41 | + */ |
|
| 42 | + public static function forDatabase(): DatabaseOptionBuilder |
|
| 43 | + { |
|
| 44 | 44 | return new DatabaseOptionBuilder(); |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -13,101 +13,101 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class DatabaseOptionBuilder |
| 15 | 15 | { |
| 16 | - /** @var ?string */ |
|
| 17 | - private ?string $table = null; |
|
| 18 | - |
|
| 19 | - /** @var ?string */ |
|
| 20 | - private ?string $expirationTime = null; |
|
| 21 | - |
|
| 22 | - /** @var ?string */ |
|
| 23 | - private ?string $flushAfter = null; |
|
| 24 | - |
|
| 25 | - /** @var array */ |
|
| 26 | - private array $options = []; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Sets the database table used for cache storage. |
|
| 30 | - * |
|
| 31 | - * @param string $table |
|
| 32 | - * @return $this |
|
| 33 | - */ |
|
| 34 | - public function table(string $table): self |
|
| 35 | - { |
|
| 16 | + /** @var ?string */ |
|
| 17 | + private ?string $table = null; |
|
| 18 | + |
|
| 19 | + /** @var ?string */ |
|
| 20 | + private ?string $expirationTime = null; |
|
| 21 | + |
|
| 22 | + /** @var ?string */ |
|
| 23 | + private ?string $flushAfter = null; |
|
| 24 | + |
|
| 25 | + /** @var array */ |
|
| 26 | + private array $options = []; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Sets the database table used for cache storage. |
|
| 30 | + * |
|
| 31 | + * @param string $table |
|
| 32 | + * @return $this |
|
| 33 | + */ |
|
| 34 | + public function table(string $table): self |
|
| 35 | + { |
|
| 36 | 36 | $this->table = $table; |
| 37 | 37 | return $this; |
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Sets the default expiration time for records. |
|
| 42 | - * |
|
| 43 | - * @param ?string $expirationTime |
|
| 44 | - * @return $this|TimeBuilder |
|
| 45 | - */ |
|
| 46 | - public function expirationTime(?string $expirationTime = null) |
|
| 47 | - { |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Sets the default expiration time for records. |
|
| 42 | + * |
|
| 43 | + * @param ?string $expirationTime |
|
| 44 | + * @return $this|TimeBuilder |
|
| 45 | + */ |
|
| 46 | + public function expirationTime(?string $expirationTime = null) |
|
| 47 | + { |
|
| 48 | 48 | if (!is_null($expirationTime)) { |
| 49 | - $this->expirationTime = $expirationTime; |
|
| 50 | - return $this; |
|
| 49 | + $this->expirationTime = $expirationTime; |
|
| 50 | + return $this; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | return new TimeBuilder(function ($formattedTime) { |
| 54 | - $this->expirationTime = $formattedTime; |
|
| 54 | + $this->expirationTime = $formattedTime; |
|
| 55 | 55 | }, $this); |
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Sets an auto-flush interval for database cache. |
|
| 60 | - * |
|
| 61 | - * @param ?string $flushAfter |
|
| 62 | - * @return $this|TimeBuilder |
|
| 63 | - */ |
|
| 64 | - public function flushAfter(?string $flushAfter = null) |
|
| 65 | - { |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Sets an auto-flush interval for database cache. |
|
| 60 | + * |
|
| 61 | + * @param ?string $flushAfter |
|
| 62 | + * @return $this|TimeBuilder |
|
| 63 | + */ |
|
| 64 | + public function flushAfter(?string $flushAfter = null) |
|
| 65 | + { |
|
| 66 | 66 | if (!is_null($flushAfter)) { |
| 67 | - $this->flushAfter = mb_strtolower($flushAfter, 'UTF-8'); |
|
| 68 | - return $this; |
|
| 67 | + $this->flushAfter = mb_strtolower($flushAfter, 'UTF-8'); |
|
| 68 | + return $this; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return new TimeBuilder(function ($formattedTime) { |
| 72 | - $this->flushAfter = $formattedTime; |
|
| 72 | + $this->flushAfter = $formattedTime; |
|
| 73 | 73 | }, $this); |
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Builds the options array. |
|
| 78 | - * |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function build(): array |
|
| 82 | - { |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Builds the options array. |
|
| 78 | + * |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function build(): array |
|
| 82 | + { |
|
| 83 | 83 | return $this->validated(); |
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Validate and assemble options. |
|
| 88 | - * @return array |
|
| 89 | - */ |
|
| 90 | - private function validated(): array |
|
| 91 | - { |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Validate and assemble options. |
|
| 88 | + * @return array |
|
| 89 | + */ |
|
| 90 | + private function validated(): array |
|
| 91 | + { |
|
| 92 | 92 | foreach ($this->properties() as $key => $value) { |
| 93 | - if (!empty($value)) { |
|
| 93 | + if (!empty($value)) { |
|
| 94 | 94 | $this->options[$key] = $value; |
| 95 | - } |
|
| 95 | + } |
|
| 96 | 96 | } |
| 97 | 97 | return $this->options; |
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Returns current properties. |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - private function properties(): array |
|
| 105 | - { |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Returns current properties. |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + private function properties(): array |
|
| 105 | + { |
|
| 106 | 106 | return [ |
| 107 | - 'table' => $this->table, |
|
| 108 | - 'expirationTime' => $this->expirationTime, |
|
| 109 | - 'flushAfter' => $this->flushAfter, |
|
| 107 | + 'table' => $this->table, |
|
| 108 | + 'expirationTime' => $this->expirationTime, |
|
| 109 | + 'flushAfter' => $this->flushAfter, |
|
| 110 | 110 | ]; |
| 111 | - } |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | |