@@ -23,40 +23,40 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Logs a info message. |
|
27 | - * |
|
28 | - * @return void |
|
29 | - */ |
|
26 | + * Logs a info message. |
|
27 | + * |
|
28 | + * @return void |
|
29 | + */ |
|
30 | 30 | public function info($message): void |
31 | 31 | { |
32 | 32 | $this->log('INFO', $message); |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Logs a warning message. |
|
37 | - * |
|
38 | - * @return void |
|
39 | - */ |
|
36 | + * Logs a warning message. |
|
37 | + * |
|
38 | + * @return void |
|
39 | + */ |
|
40 | 40 | public function warning($message): void |
41 | 41 | { |
42 | 42 | $this->log('WARNING', $message); |
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | - * Logs an error message. |
|
47 | - * |
|
48 | - * @return void |
|
49 | - */ |
|
46 | + * Logs an error message. |
|
47 | + * |
|
48 | + * @return void |
|
49 | + */ |
|
50 | 50 | public function error($message): void |
51 | 51 | { |
52 | 52 | $this->log('ERROR', $message); |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | - * Logs a debug message. |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
56 | + * Logs a debug message. |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | 60 | public function debug($message): void |
61 | 61 | { |
62 | 62 | $this->log('DEBUG', $message); |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | - * Rotates the log file if it exceeds the maximum size. |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
77 | + * Rotates the log file if it exceeds the maximum size. |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | 81 | private function rotateLog(): void |
82 | 82 | { |
83 | 83 | if (file_exists($this->logFile) && filesize($this->logFile) >= $this->maxFileSize) { |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | - * Logs a message to the log file. |
|
91 | - * |
|
92 | - * @param mixed $level |
|
93 | - * @param string $message |
|
94 | - * @return void |
|
95 | - */ |
|
90 | + * Logs a message to the log file. |
|
91 | + * |
|
92 | + * @param mixed $level |
|
93 | + * @param string $message |
|
94 | + * @return void |
|
95 | + */ |
|
96 | 96 | private function log(mixed $level, string $message): void |
97 | 97 | { |
98 | 98 | if (!$this->shouldLog($level)) { |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | class Connect |
15 | 15 | { |
16 | 16 | /** |
17 | - * The default connection type. |
|
18 | - * Currently, it supports 'mysql', 'sqlite', and 'pgsql'. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
17 | + * The default connection type. |
|
18 | + * Currently, it supports 'mysql', 'sqlite', and 'pgsql'. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | 22 | public static string $connection = 'sqlite'; |
23 | 23 | |
24 | 24 | /** |
25 | - * Holds the last error encountered during connection attempts. |
|
26 | - * |
|
27 | - * @var PDOException|null |
|
28 | - */ |
|
25 | + * Holds the last error encountered during connection attempts. |
|
26 | + * |
|
27 | + * @var PDOException|null |
|
28 | + */ |
|
29 | 29 | private static ?PDOException $error = null; |
30 | 30 | |
31 | 31 | |
@@ -62,20 +62,20 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | - * Gets the current connection type. |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
65 | + * Gets the current connection type. |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | 69 | public static function getConnection(): string |
70 | 70 | { |
71 | 71 | return self::$connection; |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | - * Returns the last error encountered during connection attempts.\ |
|
76 | - * |
|
77 | - * @return PDOException|null |
|
78 | - */ |
|
75 | + * Returns the last error encountered during connection attempts.\ |
|
76 | + * |
|
77 | + * @return PDOException|null |
|
78 | + */ |
|
79 | 79 | public static function getError(): ?PDOException |
80 | 80 | { |
81 | 81 | return self::$error; |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | * This class is designed to be used statically, so it cannot be instantiated. |
87 | 87 | * |
88 | 88 | * @return void |
89 | - */ |
|
89 | + */ |
|
90 | 90 | private function __construct() {} |
91 | 91 | |
92 | 92 | /** |
93 | - * Prevents cloning of the Connect instance. |
|
94 | - * |
|
95 | - * @return void |
|
96 | - */ |
|
93 | + * Prevents cloning of the Connect instance. |
|
94 | + * |
|
95 | + * @return void |
|
96 | + */ |
|
97 | 97 | private function __clone() {} |
98 | 98 | } |
@@ -82,15 +82,15 @@ |
||
82 | 82 | return $ttl; |
83 | 83 | } |
84 | 84 | |
85 | - /** |
|
86 | - * Generates an array identifier for cache data. |
|
87 | - * |
|
88 | - * @param mixed $currentCacheData |
|
89 | - * @param mixed $cacheData |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData): array |
|
93 | - { |
|
85 | + /** |
|
86 | + * Generates an array identifier for cache data. |
|
87 | + * |
|
88 | + * @param mixed $currentCacheData |
|
89 | + * @param mixed $cacheData |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData): array |
|
93 | + { |
|
94 | 94 | return CacheerHelper::arrayIdentifier($currentCacheData, $cacheData); |
95 | - } |
|
95 | + } |
|
96 | 96 | } |
@@ -12,24 +12,24 @@ discard block |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | /** |
15 | - * Gets the path to the SQLite database file. |
|
16 | - * |
|
17 | - * @param string $database |
|
18 | - * @param ?string $path |
|
19 | - * @return string |
|
20 | - */ |
|
15 | + * Gets the path to the SQLite database file. |
|
16 | + * |
|
17 | + * @param string $database |
|
18 | + * @param ?string $path |
|
19 | + * @return string |
|
20 | + */ |
|
21 | 21 | public static function database(string $database = 'database.sqlite', ?string $path = null): string |
22 | 22 | { |
23 | 23 | return self::getDynamicSqliteDbPath($database, $path); |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | - * Gets the path to the SQLite database file dynamically. |
|
28 | - * |
|
29 | - * @param string $database |
|
30 | - * @param ?string $path |
|
31 | - * @return string |
|
32 | - */ |
|
27 | + * Gets the path to the SQLite database file dynamically. |
|
28 | + * |
|
29 | + * @param string $database |
|
30 | + * @param ?string $path |
|
31 | + * @return string |
|
32 | + */ |
|
33 | 33 | private static function getDynamicSqliteDbPath(string $database, ?string $path = null): string |
34 | 34 | { |
35 | 35 | $rootPath = EnvHelper::getRootPath(); |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * Creates the database directory if it does not exist. |
|
51 | - * |
|
52 | - * @param string $databaseDir |
|
53 | - * @return void |
|
54 | - */ |
|
50 | + * Creates the database directory if it does not exist. |
|
51 | + * |
|
52 | + * @param string $databaseDir |
|
53 | + * @return void |
|
54 | + */ |
|
55 | 55 | private static function createDatabaseDir(string $databaseDir): void |
56 | 56 | { |
57 | 57 | if (!is_dir($databaseDir)) { |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Creates the SQLite database file if it does not exist. |
|
64 | - * |
|
65 | - * @param string $dbFile |
|
66 | - * @return void |
|
67 | - */ |
|
63 | + * Creates the SQLite database file if it does not exist. |
|
64 | + * |
|
65 | + * @param string $dbFile |
|
66 | + * @return void |
|
67 | + */ |
|
68 | 68 | private static function createDatabaseFile(string $dbFile): void |
69 | 69 | { |
70 | 70 | if (!file_exists($dbFile)) { |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | - * Checks if the database name has the correct extension. |
|
77 | - * If not, appends '.sqlite' to the name. |
|
78 | - * |
|
79 | - * @param string $database |
|
80 | - * @return string |
|
81 | - */ |
|
76 | + * Checks if the database name has the correct extension. |
|
77 | + * If not, appends '.sqlite' to the name. |
|
78 | + * |
|
79 | + * @param string $database |
|
80 | + * @return string |
|
81 | + */ |
|
82 | 82 | private static function checkExtension(string $database): string |
83 | 83 | { |
84 | 84 | if (!str_contains($database, '.sqlite')) { |
@@ -13,29 +13,29 @@ discard block |
||
13 | 13 | class CacheRedisHelper |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * serializes or unserializes data based on the $serialize flag. |
|
18 | - * |
|
19 | - * @param mixed $data |
|
20 | - * @param bool $serialize |
|
21 | - * @return mixed |
|
22 | - */ |
|
23 | - public static function serialize(mixed $data, bool $serialize = true): mixed |
|
24 | - { |
|
16 | + /** |
|
17 | + * serializes or unserializes data based on the $serialize flag. |
|
18 | + * |
|
19 | + * @param mixed $data |
|
20 | + * @param bool $serialize |
|
21 | + * @return mixed |
|
22 | + */ |
|
23 | + public static function serialize(mixed $data, bool $serialize = true): mixed |
|
24 | + { |
|
25 | 25 | if($serialize) { |
26 | - return serialize($data); |
|
26 | + return serialize($data); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | return unserialize($data); |
30 | 30 | |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | 33 | /** |
34 | - * Validates a cache item. |
|
35 | - * |
|
36 | - * @param array $item |
|
37 | - * @return void |
|
38 | - */ |
|
34 | + * Validates a cache item. |
|
35 | + * |
|
36 | + * @param array $item |
|
37 | + * @return void |
|
38 | + */ |
|
39 | 39 | public static function validateCacheItem(array $item): void |
40 | 40 | { |
41 | 41 | CacheerHelper::validateCacheItem( |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | return CacheerHelper::mergeCacheData($cacheData); |
56 | 56 | } |
57 | 57 | |
58 | - /** |
|
59 | - * Generates an array identifier for cache data. |
|
60 | - * |
|
61 | - * @param mixed $currentCacheData |
|
62 | - * @param mixed $cacheData |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData): array |
|
66 | - { |
|
67 | - return CacheerHelper::arrayIdentifier($currentCacheData, $cacheData); |
|
68 | - } |
|
58 | + /** |
|
59 | + * Generates an array identifier for cache data. |
|
60 | + * |
|
61 | + * @param mixed $currentCacheData |
|
62 | + * @param mixed $cacheData |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData): array |
|
66 | + { |
|
67 | + return CacheerHelper::arrayIdentifier($currentCacheData, $cacheData); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
71 | 71 |
@@ -13,111 +13,111 @@ discard block |
||
13 | 13 | class ArrayCacheStore implements CacheerInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $arrayStore |
|
18 | - */ |
|
19 | - private array $arrayStore = []; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var boolean |
|
23 | - */ |
|
24 | - private bool $success = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - private string $message = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var ?CacheLogger |
|
33 | - */ |
|
34 | - private ?CacheLogger $logger = null; |
|
35 | - |
|
36 | - /** |
|
37 | - * ArrayCacheStore constructor. |
|
38 | - * |
|
39 | - * @param string $logPath |
|
40 | - */ |
|
41 | - public function __construct(string $logPath) |
|
42 | - { |
|
16 | + /** |
|
17 | + * @param array $arrayStore |
|
18 | + */ |
|
19 | + private array $arrayStore = []; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var boolean |
|
23 | + */ |
|
24 | + private bool $success = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + private string $message = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var ?CacheLogger |
|
33 | + */ |
|
34 | + private ?CacheLogger $logger = null; |
|
35 | + |
|
36 | + /** |
|
37 | + * ArrayCacheStore constructor. |
|
38 | + * |
|
39 | + * @param string $logPath |
|
40 | + */ |
|
41 | + public function __construct(string $logPath) |
|
42 | + { |
|
43 | 43 | $this->logger = new CacheLogger($logPath); |
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Appends data to an existing cache item. |
|
48 | - * |
|
49 | - * @param string $cacheKey |
|
50 | - * @param mixed $cacheData |
|
51 | - * @param string $namespace |
|
52 | - * @return bool |
|
53 | - */ |
|
54 | - public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool |
|
55 | - { |
|
56 | - $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
|
57 | - |
|
58 | - if (!$this->has($cacheKey, $namespace)) { |
|
59 | - $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false); |
|
60 | - $this->logger->debug("{$this->getMessage()} from array driver."); |
|
61 | - return false; |
|
62 | - } |
|
63 | - |
|
64 | - $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData); |
|
65 | - $this->setMessage("Cache appended successfully", true); |
|
66 | - return true; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Builds a unique key for the array store. |
|
71 | - * |
|
72 | - * @param string $cacheKey |
|
73 | - * @param string $namespace |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - private function buildArrayKey(string $cacheKey, string $namespace = ''): string |
|
77 | - { |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Appends data to an existing cache item. |
|
48 | + * |
|
49 | + * @param string $cacheKey |
|
50 | + * @param mixed $cacheData |
|
51 | + * @param string $namespace |
|
52 | + * @return bool |
|
53 | + */ |
|
54 | + public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool |
|
55 | + { |
|
56 | + $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
|
57 | + |
|
58 | + if (!$this->has($cacheKey, $namespace)) { |
|
59 | + $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false); |
|
60 | + $this->logger->debug("{$this->getMessage()} from array driver."); |
|
61 | + return false; |
|
62 | + } |
|
63 | + |
|
64 | + $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData); |
|
65 | + $this->setMessage("Cache appended successfully", true); |
|
66 | + return true; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Builds a unique key for the array store. |
|
71 | + * |
|
72 | + * @param string $cacheKey |
|
73 | + * @param string $namespace |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + private function buildArrayKey(string $cacheKey, string $namespace = ''): string |
|
77 | + { |
|
78 | 78 | return !empty($namespace) ? ($namespace . ':' . $cacheKey) : $cacheKey; |
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Clears a specific cache item. |
|
83 | - * |
|
84 | - * @param string $cacheKey |
|
85 | - * @param string $namespace |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - public function clearCache(string $cacheKey, string $namespace = ''): void |
|
89 | - { |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Clears a specific cache item. |
|
83 | + * |
|
84 | + * @param string $cacheKey |
|
85 | + * @param string $namespace |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + public function clearCache(string $cacheKey, string $namespace = ''): void |
|
89 | + { |
|
90 | 90 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
91 | 91 | unset($this->arrayStore[$arrayStoreKey]); |
92 | 92 | $this->setMessage("Cache cleared successfully", true); |
93 | 93 | $this->logger->debug("{$this->getMessage()} from array driver."); |
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Decrements a cache item by a specified amount. |
|
98 | - * |
|
99 | - * @param string $cacheKey |
|
100 | - * @param int $amount |
|
101 | - * @param string $namespace |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
|
105 | - { |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Decrements a cache item by a specified amount. |
|
98 | + * |
|
99 | + * @param string $cacheKey |
|
100 | + * @param int $amount |
|
101 | + * @param string $namespace |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
|
105 | + { |
|
106 | 106 | return $this->increment($cacheKey, ($amount * -1), $namespace); |
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Flushes all cache items. |
|
111 | - * |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - public function flushCache(): void |
|
115 | - { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Flushes all cache items. |
|
111 | + * |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + public function flushCache(): void |
|
115 | + { |
|
116 | 116 | unset($this->arrayStore); |
117 | 117 | $this->arrayStore = []; |
118 | 118 | $this->setMessage("Cache flushed successfully", true); |
119 | 119 | $this->logger->debug("{$this->getMessage()} from array driver."); |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Stores a cache item permanently. |
@@ -126,234 +126,234 @@ discard block |
||
126 | 126 | * @param mixed $cacheData |
127 | 127 | * @return void |
128 | 128 | */ |
129 | - public function forever(string $cacheKey, mixed $cacheData): void |
|
130 | - { |
|
129 | + public function forever(string $cacheKey, mixed $cacheData): void |
|
130 | + { |
|
131 | 131 | $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000); |
132 | 132 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Retrieves a single cache item. |
|
137 | - * |
|
138 | - * @param string $cacheKey |
|
139 | - * @param string $namespace |
|
140 | - * @param int|string $ttl |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed |
|
144 | - { |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Retrieves a single cache item. |
|
137 | + * |
|
138 | + * @param string $cacheKey |
|
139 | + * @param string $namespace |
|
140 | + * @param int|string $ttl |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed |
|
144 | + { |
|
145 | 145 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
146 | 146 | |
147 | 147 | if (!$this->has($cacheKey, $namespace)) { |
148 | - $this->handleCacheNotFound(); |
|
149 | - return false; |
|
148 | + $this->handleCacheNotFound(); |
|
149 | + return false; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $cacheData = $this->arrayStore[$arrayStoreKey]; |
153 | 153 | if ($this->isExpired($cacheData)) { |
154 | - $this->handleCacheExpired($arrayStoreKey); |
|
155 | - return false; |
|
154 | + $this->handleCacheExpired($arrayStoreKey); |
|
155 | + return false; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | $this->setMessage("Cache retrieved successfully", true); |
159 | 159 | $this->logger->debug("{$this->getMessage()} from array driver."); |
160 | 160 | return $this->serialize($cacheData['cacheData'], false); |
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Verify if the cache is expired. |
|
165 | - * |
|
166 | - * @param array $cacheData |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - private function isExpired(array $cacheData): bool |
|
170 | - { |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Verify if the cache is expired. |
|
165 | + * |
|
166 | + * @param array $cacheData |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + private function isExpired(array $cacheData): bool |
|
170 | + { |
|
171 | 171 | $expirationTime = $cacheData['expirationTime'] ?? 0; |
172 | 172 | $now = time(); |
173 | 173 | return $expirationTime !== 0 && $now >= $expirationTime; |
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Handles the case when cache data is not found. |
|
178 | - * |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - private function handleCacheNotFound(): void |
|
182 | - { |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Handles the case when cache data is not found. |
|
178 | + * |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + private function handleCacheNotFound(): void |
|
182 | + { |
|
183 | 183 | $this->setMessage("cacheData not found, does not exists or expired", false); |
184 | 184 | $this->logger->debug("{$this->getMessage()} from array driver."); |
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Handles the case when cache data has expired. |
|
189 | - * |
|
190 | - * @param string $arrayStoreKey |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - private function handleCacheExpired(string $arrayStoreKey): void |
|
194 | - { |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Handles the case when cache data has expired. |
|
189 | + * |
|
190 | + * @param string $arrayStoreKey |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + private function handleCacheExpired(string $arrayStoreKey): void |
|
194 | + { |
|
195 | 195 | $parts = explode(':', $arrayStoreKey, 2); |
196 | 196 | if (count($parts) === 2) { |
197 | - list($np, $key) = $parts; |
|
197 | + list($np, $key) = $parts; |
|
198 | 198 | } else { |
199 | - $np = ''; |
|
200 | - $key = $arrayStoreKey; |
|
199 | + $np = ''; |
|
200 | + $key = $arrayStoreKey; |
|
201 | 201 | } |
202 | 202 | $this->clearCache($key, $np); |
203 | 203 | $this->setMessage("cacheKey: {$key} has expired.", false); |
204 | 204 | $this->logger->debug("{$this->getMessage()} from array driver."); |
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Gets all items in a specific namespace. |
|
209 | - * |
|
210 | - * @param string $namespace |
|
211 | - * @return array |
|
212 | - */ |
|
213 | - public function getAll(string $namespace = ''): array |
|
214 | - { |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Gets all items in a specific namespace. |
|
209 | + * |
|
210 | + * @param string $namespace |
|
211 | + * @return array |
|
212 | + */ |
|
213 | + public function getAll(string $namespace = ''): array |
|
214 | + { |
|
215 | 215 | $results = []; |
216 | 216 | foreach ($this->arrayStore as $key => $data) { |
217 | - if (str_starts_with($key, $namespace . ':') || empty($namespace)) { |
|
217 | + if (str_starts_with($key, $namespace . ':') || empty($namespace)) { |
|
218 | 218 | $results[$key] = $this->serialize($data['cacheData'], false); |
219 | - } |
|
219 | + } |
|
220 | 220 | } |
221 | 221 | return $results; |
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Retrieves multiple cache items by their keys. |
|
226 | - * |
|
227 | - * @param array $cacheKeys |
|
228 | - * @param string $namespace |
|
229 | - * @param string|int $ttl |
|
230 | - * @return array |
|
231 | - */ |
|
232 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array |
|
233 | - { |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Retrieves multiple cache items by their keys. |
|
226 | + * |
|
227 | + * @param array $cacheKeys |
|
228 | + * @param string $namespace |
|
229 | + * @param string|int $ttl |
|
230 | + * @return array |
|
231 | + */ |
|
232 | + public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array |
|
233 | + { |
|
234 | 234 | $results = []; |
235 | 235 | foreach ($cacheKeys as $cacheKey) { |
236 | - $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl); |
|
236 | + $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl); |
|
237 | 237 | } |
238 | 238 | return $results; |
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Checks if a cache item exists. |
|
243 | - * |
|
244 | - * @param string $cacheKey |
|
245 | - * @param string $namespace |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - public function has(string $cacheKey, string $namespace = ''): bool |
|
249 | - { |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Checks if a cache item exists. |
|
243 | + * |
|
244 | + * @param string $cacheKey |
|
245 | + * @param string $namespace |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + public function has(string $cacheKey, string $namespace = ''): bool |
|
249 | + { |
|
250 | 250 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
251 | 251 | $exists = isset($this->arrayStore[$arrayStoreKey]) && time() < $this->arrayStore[$arrayStoreKey]['expirationTime']; |
252 | 252 | |
253 | 253 | $this->setMessage( |
254 | - $exists ? "Cache key: {$cacheKey} exists and it's available!" : "Cache key: {$cacheKey} does not exist or it's expired!", |
|
255 | - $exists |
|
254 | + $exists ? "Cache key: {$cacheKey} exists and it's available!" : "Cache key: {$cacheKey} does not exist or it's expired!", |
|
255 | + $exists |
|
256 | 256 | ); |
257 | 257 | $this->logger->debug("{$this->getMessage()} from array driver."); |
258 | 258 | |
259 | 259 | return $exists; |
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Increments a cache item by a specified amount. |
|
264 | - * |
|
265 | - * @param string $cacheKey |
|
266 | - * @param int $amount |
|
267 | - * @param string $namespace |
|
268 | - * @return bool |
|
269 | - */ |
|
270 | - public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
|
271 | - { |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Increments a cache item by a specified amount. |
|
264 | + * |
|
265 | + * @param string $cacheKey |
|
266 | + * @param int $amount |
|
267 | + * @param string $namespace |
|
268 | + * @return bool |
|
269 | + */ |
|
270 | + public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
|
271 | + { |
|
272 | 272 | $cacheData = $this->getCache($cacheKey, $namespace); |
273 | 273 | |
274 | 274 | if(!empty($cacheData) && is_numeric($cacheData)) { |
275 | - $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
|
276 | - $this->setMessage($this->getMessage(), $this->isSuccess()); |
|
277 | - return true; |
|
275 | + $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
|
276 | + $this->setMessage($this->getMessage(), $this->isSuccess()); |
|
277 | + return true; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | return false; |
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Checks if the operation was successful. |
|
285 | - * |
|
286 | - * @return boolean |
|
287 | - */ |
|
288 | - public function isSuccess(): bool |
|
289 | - { |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Checks if the operation was successful. |
|
285 | + * |
|
286 | + * @return boolean |
|
287 | + */ |
|
288 | + public function isSuccess(): bool |
|
289 | + { |
|
290 | 290 | return $this->success; |
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Gets the last message. |
|
295 | - * |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - public function getMessage(): string |
|
299 | - { |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Gets the last message. |
|
295 | + * |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + public function getMessage(): string |
|
299 | + { |
|
300 | 300 | return $this->message; |
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Stores an item in the cache with a specific TTL. |
|
305 | - * |
|
306 | - * @param string $cacheKey |
|
307 | - * @param mixed $cacheData |
|
308 | - * @param string $namespace |
|
309 | - * @param int|string $ttl |
|
310 | - * @return bool |
|
311 | - */ |
|
312 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
|
313 | - { |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Stores an item in the cache with a specific TTL. |
|
305 | + * |
|
306 | + * @param string $cacheKey |
|
307 | + * @param mixed $cacheData |
|
308 | + * @param string $namespace |
|
309 | + * @param int|string $ttl |
|
310 | + * @return bool |
|
311 | + */ |
|
312 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
|
313 | + { |
|
314 | 314 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
315 | 315 | |
316 | 316 | $this->arrayStore[$arrayStoreKey] = [ |
317 | - 'cacheData' => serialize($cacheData), |
|
318 | - 'expirationTime' => time() + $ttl |
|
317 | + 'cacheData' => serialize($cacheData), |
|
318 | + 'expirationTime' => time() + $ttl |
|
319 | 319 | ]; |
320 | 320 | |
321 | 321 | $this->setMessage("Cache stored successfully", true); |
322 | 322 | $this->logger->debug("{$this->getMessage()} from Array driver."); |
323 | 323 | return true; |
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Stores multiple items in the cache in batches. |
|
328 | - * |
|
329 | - * @param array $items |
|
330 | - * @param string $namespace |
|
331 | - * @param int $batchSize |
|
332 | - * @return void |
|
333 | - */ |
|
334 | - public function putMany(array $items, string $namespace = '', int $batchSize = 100): void |
|
335 | - { |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Stores multiple items in the cache in batches. |
|
328 | + * |
|
329 | + * @param array $items |
|
330 | + * @param string $namespace |
|
331 | + * @param int $batchSize |
|
332 | + * @return void |
|
333 | + */ |
|
334 | + public function putMany(array $items, string $namespace = '', int $batchSize = 100): void |
|
335 | + { |
|
336 | 336 | $chunks = array_chunk($items, $batchSize, true); |
337 | 337 | |
338 | 338 | foreach ($chunks as $chunk) { |
339 | - foreach ($chunk as $key => $data) { |
|
340 | - $this->putCache($data['cacheKey'], $data['cacheData'], $namespace); |
|
339 | + foreach ($chunk as $key => $data) { |
|
340 | + $this->putCache($data['cacheKey'], $data['cacheData'], $namespace); |
|
341 | + } |
|
341 | 342 | } |
342 | - } |
|
343 | 343 | $this->setMessage("{$this->getMessage()}", $this->isSuccess()); |
344 | 344 | $this->logger->debug("{$this->getMessage()} from Array driver."); |
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Renews the expiration time of a cache item. |
|
349 | - * |
|
350 | - * @param string $cacheKey |
|
351 | - * @param string|int $ttl |
|
352 | - * @param string $namespace |
|
353 | - * @return void |
|
354 | - */ |
|
355 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void |
|
356 | - { |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Renews the expiration time of a cache item. |
|
349 | + * |
|
350 | + * @param string $cacheKey |
|
351 | + * @param string|int $ttl |
|
352 | + * @param string $namespace |
|
353 | + * @return void |
|
354 | + */ |
|
355 | + public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void |
|
356 | + { |
|
357 | 357 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
358 | 358 | |
359 | 359 | if (isset($this->arrayStore[$arrayStoreKey])) { |
@@ -361,31 +361,31 @@ discard block |
||
361 | 361 | $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds; |
362 | 362 | $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true); |
363 | 363 | $this->logger->debug("{$this->getMessage()} from array driver."); |
364 | - } |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Sets a message and its success status. |
|
369 | - * |
|
370 | - * @param string $message |
|
371 | - * @param boolean $success |
|
372 | - * @return void |
|
373 | - */ |
|
374 | - private function setMessage(string $message, bool $success): void |
|
375 | - { |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Sets a message and its success status. |
|
369 | + * |
|
370 | + * @param string $message |
|
371 | + * @param boolean $success |
|
372 | + * @return void |
|
373 | + */ |
|
374 | + private function setMessage(string $message, bool $success): void |
|
375 | + { |
|
376 | 376 | $this->message = $message; |
377 | 377 | $this->success = $success; |
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Serializes or unserializes data based on the flag. |
|
382 | - * |
|
383 | - * @param mixed $data |
|
384 | - * @param bool $serialize |
|
385 | - * @return mixed |
|
386 | - */ |
|
387 | - private function serialize(mixed $data, bool $serialize = true): mixed |
|
388 | - { |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Serializes or unserializes data based on the flag. |
|
382 | + * |
|
383 | + * @param mixed $data |
|
384 | + * @param bool $serialize |
|
385 | + * @return mixed |
|
386 | + */ |
|
387 | + private function serialize(mixed $data, bool $serialize = true): mixed |
|
388 | + { |
|
389 | 389 | return $serialize ? serialize($data) : unserialize($data); |
390 | - } |
|
390 | + } |
|
391 | 391 | } |
@@ -13,29 +13,29 @@ discard block |
||
13 | 13 | class CacheMutator |
14 | 14 | { |
15 | 15 | /** |
16 | - * @var Cacheer |
|
17 | - */ |
|
16 | + * @var Cacheer |
|
17 | + */ |
|
18 | 18 | private Cacheer $cacheer; |
19 | 19 | |
20 | 20 | /** |
21 | - * CacheMutator constructor. |
|
22 | - * |
|
23 | - * @param Cacheer $cacheer |
|
24 | - */ |
|
21 | + * CacheMutator constructor. |
|
22 | + * |
|
23 | + * @param Cacheer $cacheer |
|
24 | + */ |
|
25 | 25 | public function __construct(Cacheer $cacheer) |
26 | 26 | { |
27 | 27 | $this->cacheer = $cacheer; |
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | - * Adds a cache item if it does not already exist. |
|
32 | - * |
|
33 | - * @param string $cacheKey |
|
34 | - * @param mixed $cacheData |
|
35 | - * @param string $namespace |
|
36 | - * @param int|string $ttl |
|
37 | - * @return bool |
|
38 | - */ |
|
31 | + * Adds a cache item if it does not already exist. |
|
32 | + * |
|
33 | + * @param string $cacheKey |
|
34 | + * @param mixed $cacheData |
|
35 | + * @param string $namespace |
|
36 | + * @param int|string $ttl |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | 39 | public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
40 | 40 | { |
41 | 41 | if (!empty($this->cacheer->getCache($cacheKey, $namespace))) { |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | - * Appends data to an existing cache item. |
|
53 | - * |
|
54 | - * @param string $cacheKey |
|
55 | - * @param mixed $cacheData |
|
56 | - * @param string $namespace |
|
57 | - * @return bool |
|
58 | - */ |
|
52 | + * Appends data to an existing cache item. |
|
53 | + * |
|
54 | + * @param string $cacheKey |
|
55 | + * @param mixed $cacheData |
|
56 | + * @param string $namespace |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | 59 | public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool |
60 | 60 | { |
61 | 61 | $this->cacheer->cacheStore->appendCache($cacheKey, $cacheData, $namespace); |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | - * Clears a specific cache item. |
|
69 | - * |
|
70 | - * @param string $cacheKey |
|
71 | - * @param string $namespace |
|
72 | - * @return bool |
|
73 | - */ |
|
68 | + * Clears a specific cache item. |
|
69 | + * |
|
70 | + * @param string $cacheKey |
|
71 | + * @param string $namespace |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | 74 | public function clearCache(string $cacheKey, string $namespace = ''): bool |
75 | 75 | { |
76 | 76 | $this->cacheer->cacheStore->clearCache($cacheKey, $namespace); |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | - * Decrements a numeric cache item by a specified amount. |
|
84 | - * |
|
85 | - * @param string $cacheKey |
|
86 | - * @param int $amount |
|
87 | - * @param string $namespace |
|
88 | - * @return bool |
|
89 | - */ |
|
83 | + * Decrements a numeric cache item by a specified amount. |
|
84 | + * |
|
85 | + * @param string $cacheKey |
|
86 | + * @param int $amount |
|
87 | + * @param string $namespace |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | 90 | public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
91 | 91 | { |
92 | 92 | return $this->increment($cacheKey, ($amount * -1), $namespace); |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | - * Flushes the entire cache. |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
111 | + * Flushes the entire cache. |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | 115 | public function flushCache(): bool |
116 | 116 | { |
117 | 117 | $this->cacheer->cacheStore->flushCache(); |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | - * Puts multiple cache items in a batch. |
|
164 | - * |
|
165 | - * @param array $items |
|
166 | - * @param string $namespace |
|
167 | - * @param int $batchSize |
|
168 | - * @return bool |
|
169 | - */ |
|
163 | + * Puts multiple cache items in a batch. |
|
164 | + * |
|
165 | + * @param array $items |
|
166 | + * @param string $namespace |
|
167 | + * @param int $batchSize |
|
168 | + * @return bool |
|
169 | + */ |
|
170 | 170 | public function putMany(array $items, string $namespace = '', int $batchSize = 100): bool |
171 | 171 | { |
172 | 172 | $this->cacheer->cacheStore->putMany($items, $namespace, $batchSize); |
@@ -176,13 +176,13 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Renews the cache item with a new TTL. |
|
180 | - * |
|
181 | - * @param string $cacheKey |
|
182 | - * @param int|string $ttl |
|
183 | - * @param string $namespace |
|
184 | - * @return bool |
|
185 | - */ |
|
179 | + * Renews the cache item with a new TTL. |
|
180 | + * |
|
181 | + * @param string $cacheKey |
|
182 | + * @param int|string $ttl |
|
183 | + * @param string $namespace |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | 186 | public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): bool |
187 | 187 | { |
188 | 188 | $this->cacheer->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
@@ -35,8 +35,8 @@ |
||
35 | 35 | 'driver' => 'file', |
36 | 36 | 'path' => '/tmp/cache', |
37 | 37 | ]; |
38 | - Cacheer::setUp($options); |
|
39 | - self::assertSame($options, Cacheer::getOptions()); |
|
38 | + Cacheer::setUp($options); |
|
39 | + self::assertSame($options, Cacheer::getOptions()); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function testSetUpStaticWithOptionBuilder(): void |
@@ -63,66 +63,66 @@ discard block |
||
63 | 63 | final class Cacheer |
64 | 64 | { |
65 | 65 | /** |
66 | - * @var string |
|
67 | - */ |
|
66 | + * @var string |
|
67 | + */ |
|
68 | 68 | private string $message; |
69 | 69 | |
70 | 70 | /** |
71 | - * @var boolean |
|
72 | - */ |
|
71 | + * @var boolean |
|
72 | + */ |
|
73 | 73 | private bool $success; |
74 | 74 | |
75 | 75 | /** |
76 | - * @var boolean |
|
77 | - */ |
|
76 | + * @var boolean |
|
77 | + */ |
|
78 | 78 | private bool $formatted = false; |
79 | 79 | |
80 | 80 | /** |
81 | - * @var bool |
|
82 | - */ |
|
81 | + * @var bool |
|
82 | + */ |
|
83 | 83 | private bool $compression = false; |
84 | 84 | |
85 | 85 | /** |
86 | - * @var string|null |
|
87 | - */ |
|
86 | + * @var string|null |
|
87 | + */ |
|
88 | 88 | private ?string $encryptionKey = null; |
89 | 89 | |
90 | 90 | /** |
91 | - * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore |
|
92 | - */ |
|
91 | + * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore |
|
92 | + */ |
|
93 | 93 | public RedisCacheStore|DatabaseCacheStore|ArrayCacheStore|FileCacheStore $cacheStore; |
94 | 94 | |
95 | 95 | /** |
96 | - * @var array |
|
97 | - */ |
|
96 | + * @var array |
|
97 | + */ |
|
98 | 98 | public array $options = []; |
99 | 99 | |
100 | 100 | /** |
101 | - * @var CacheRetriever |
|
102 | - */ |
|
101 | + * @var CacheRetriever |
|
102 | + */ |
|
103 | 103 | private CacheRetriever $retriever; |
104 | 104 | |
105 | 105 | /** |
106 | - * @var CacheMutator |
|
107 | - */ |
|
106 | + * @var CacheMutator |
|
107 | + */ |
|
108 | 108 | private CacheMutator $mutator; |
109 | 109 | |
110 | 110 | /** |
111 | - * @var CacheConfig |
|
112 | - */ |
|
111 | + * @var CacheConfig |
|
112 | + */ |
|
113 | 113 | private CacheConfig $config; |
114 | 114 | |
115 | 115 | /** |
116 | - * @var Cacheer|null |
|
117 | - */ |
|
116 | + * @var Cacheer|null |
|
117 | + */ |
|
118 | 118 | private static ?Cacheer $staticInstance = null; |
119 | 119 | |
120 | 120 | /** |
121 | - * Cacheer constructor. |
|
122 | - * |
|
123 | - * @param array $options |
|
124 | - * @param bool $formatted |
|
125 | - * @throws RuntimeException|Exceptions\CacheFileException |
|
121 | + * Cacheer constructor. |
|
122 | + * |
|
123 | + * @param array $options |
|
124 | + * @param bool $formatted |
|
125 | + * @throws RuntimeException|Exceptions\CacheFileException |
|
126 | 126 | */ |
127 | 127 | public function __construct(array $options = [], bool $formatted = false) |
128 | 128 | { |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Enable encryption for cached data |
|
186 | - * |
|
187 | - * @param string $key |
|
188 | - * @return $this |
|
189 | - */ |
|
185 | + * Enable encryption for cached data |
|
186 | + * |
|
187 | + * @param string $key |
|
188 | + * @return $this |
|
189 | + */ |
|
190 | 190 | public function useEncryption(string $key): Cacheer |
191 | 191 | { |
192 | 192 | $this->encryptionKey = $key; |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | - * Enable or disable data compression |
|
198 | - * |
|
199 | - * @param bool $status |
|
200 | - * @return $this |
|
201 | - */ |
|
197 | + * Enable or disable data compression |
|
198 | + * |
|
199 | + * @param bool $status |
|
200 | + * @return $this |
|
201 | + */ |
|
202 | 202 | public function useCompression(bool $status = true): Cacheer |
203 | 203 | { |
204 | 204 | $this->compression = $status; |
@@ -206,43 +206,43 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | - * Enables or disables the formatter for cache data. |
|
210 | - * |
|
211 | - * @return void |
|
212 | - */ |
|
209 | + * Enables or disables the formatter for cache data. |
|
210 | + * |
|
211 | + * @return void |
|
212 | + */ |
|
213 | 213 | public function useFormatter(): void |
214 | 214 | { |
215 | 215 | $this->formatted = !$this->formatted; |
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Validates the options provided for the Cacheer instance. |
|
220 | - * |
|
221 | - * @param array $options |
|
222 | - * @return void |
|
223 | - */ |
|
219 | + * Validates the options provided for the Cacheer instance. |
|
220 | + * |
|
221 | + * @param array $options |
|
222 | + * @return void |
|
223 | + */ |
|
224 | 224 | private function validateOptions(array $options): void |
225 | 225 | { |
226 | 226 | $this->options = $options; |
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | - * Checks if the last operation was successful. |
|
231 | - * |
|
232 | - * @return bool |
|
233 | - */ |
|
230 | + * Checks if the last operation was successful. |
|
231 | + * |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | 234 | public function isSuccess(): bool |
235 | 235 | { |
236 | 236 | return $this->success; |
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
240 | - * Sets a message for the cache operation. |
|
241 | - * |
|
242 | - * @param string $message |
|
243 | - * @param boolean $success |
|
244 | - * @return void |
|
245 | - */ |
|
240 | + * Sets a message for the cache operation. |
|
241 | + * |
|
242 | + * @param string $message |
|
243 | + * @param boolean $success |
|
244 | + * @return void |
|
245 | + */ |
|
246 | 246 | private function setMessage(string $message, bool $success): void |
247 | 247 | { |
248 | 248 | $this->message = $message; |
@@ -250,10 +250,10 @@ discard block |
||
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | - * Retrieves the message from the last operation. |
|
254 | - * |
|
255 | - * @return string |
|
256 | - */ |
|
253 | + * Retrieves the message from the last operation. |
|
254 | + * |
|
255 | + * @return string |
|
256 | + */ |
|
257 | 257 | public function getMessage(): string |
258 | 258 | { |
259 | 259 | return $this->message; |