@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | - * @param string $databaseDir |
|
40 | - * @return void |
|
41 | - */ |
|
39 | + * @param string $databaseDir |
|
40 | + * @return void |
|
41 | + */ |
|
42 | 42 | private static function createDatabaseDir(string $databaseDir) |
43 | 43 | { |
44 | 44 | if (!is_dir($databaseDir)) { |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * @param string $dbFile |
|
51 | - * @return void |
|
52 | - */ |
|
50 | + * @param string $dbFile |
|
51 | + * @return void |
|
52 | + */ |
|
53 | 53 | private static function createDatabaseFile(string $dbFile) |
54 | 54 | { |
55 | 55 | if (!file_exists($dbFile)) { |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | - * @param string $database |
|
62 | - * @return string |
|
63 | - */ |
|
61 | + * @param string $database |
|
62 | + * @return string |
|
63 | + */ |
|
64 | 64 | private static function checkExtension(string $database) |
65 | 65 | { |
66 | 66 | if (strpos($database, '.sqlite') === false) { |
@@ -9,8 +9,8 @@ |
||
9 | 9 | */ |
10 | 10 | interface CacheerInterface |
11 | 11 | { |
12 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600); |
|
13 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600); |
|
12 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600); |
|
13 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600); |
|
14 | 14 | public function flushCache(); |
15 | 15 | public function clearCache(string $cacheKey, string $namespace = ''); |
16 | 16 | public function has(string $cacheKey, string $namespace = ''); |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | - * @return string|false |
|
22 | - */ |
|
21 | + * @return string|false |
|
22 | + */ |
|
23 | 23 | public function toJson() |
24 | 24 | { |
25 | 25 | return json_encode( |
@@ -31,24 +31,24 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | - * @return array |
|
35 | - */ |
|
34 | + * @return array |
|
35 | + */ |
|
36 | 36 | public function toArray() |
37 | 37 | { |
38 | 38 | return (array)$this->data; |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * @return string |
|
43 | - */ |
|
42 | + * @return string |
|
43 | + */ |
|
44 | 44 | public function toString() |
45 | 45 | { |
46 | 46 | return (string)$this->data; |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * @return object |
|
51 | - */ |
|
50 | + * @return object |
|
51 | + */ |
|
52 | 52 | public function toObject() |
53 | 53 | { |
54 | 54 | return (object)$this->data; |
@@ -82,14 +82,14 @@ |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * @param mixed $dirName |
|
86 | - * @return bool |
|
87 | - */ |
|
85 | + * @param mixed $dirName |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | 88 | private function isDir(mixed $dirName) |
89 | 89 | { |
90 | - if (is_dir($dirName)) { |
|
91 | - return true; |
|
92 | - } |
|
93 | - return mkdir($dirName, 0755, true); |
|
90 | + if (is_dir($dirName)) { |
|
91 | + return true; |
|
92 | + } |
|
93 | + return mkdir($dirName, 0755, true); |
|
94 | 94 | } |
95 | 95 | } |
@@ -23,49 +23,49 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * @return void |
|
27 | - */ |
|
26 | + * @return void |
|
27 | + */ |
|
28 | 28 | public function info($message) |
29 | 29 | { |
30 | 30 | $this->log('INFO', $message); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | - * @return void |
|
35 | - */ |
|
34 | + * @return void |
|
35 | + */ |
|
36 | 36 | public function warning($message) |
37 | 37 | { |
38 | 38 | $this->log('WARNING', $message); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * @return void |
|
43 | - */ |
|
42 | + * @return void |
|
43 | + */ |
|
44 | 44 | public function error($message) |
45 | 45 | { |
46 | 46 | $this->log('ERROR', $message); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * @return void |
|
51 | - */ |
|
50 | + * @return void |
|
51 | + */ |
|
52 | 52 | public function debug($message) |
53 | 53 | { |
54 | 54 | $this->log('DEBUG', $message); |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * @param mixed $level |
|
59 | - * @return string|int|false |
|
60 | - */ |
|
58 | + * @param mixed $level |
|
59 | + * @return string|int|false |
|
60 | + */ |
|
61 | 61 | private function shouldLog(mixed $level) |
62 | 62 | { |
63 | 63 | return array_search($level, $this->logLevels) >= array_search($this->logLevel, $this->logLevels); |
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | - * @return void |
|
68 | - */ |
|
67 | + * @return void |
|
68 | + */ |
|
69 | 69 | private function rotateLog() |
70 | 70 | { |
71 | 71 | if (file_exists($this->logFile) && filesize($this->logFile) >= $this->maxFileSize) { |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | - * @param mixed $level |
|
79 | - * @param string $message |
|
80 | - * @return void |
|
81 | - */ |
|
78 | + * @param mixed $level |
|
79 | + * @param string $message |
|
80 | + * @return void |
|
81 | + */ |
|
82 | 82 | private function log($level, $message) |
83 | 83 | { |
84 | 84 | if (!$this->shouldLog($level)) { |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public static function serialize(mixed $data, bool $serialize = true) |
21 | 21 | { |
22 | - if($serialize) { |
|
22 | + if ($serialize) { |
|
23 | 23 | return serialize($data); |
24 | 24 | } |
25 | 25 |
@@ -12,20 +12,20 @@ discard block |
||
12 | 12 | class CacheRedisHelper |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @param mixed $data |
|
17 | - * @param bool $serialize |
|
18 | - * @return mixed |
|
19 | - */ |
|
20 | - public static function serialize(mixed $data, bool $serialize = true) |
|
21 | - { |
|
15 | + /** |
|
16 | + * @param mixed $data |
|
17 | + * @param bool $serialize |
|
18 | + * @return mixed |
|
19 | + */ |
|
20 | + public static function serialize(mixed $data, bool $serialize = true) |
|
21 | + { |
|
22 | 22 | if($serialize) { |
23 | - return serialize($data); |
|
23 | + return serialize($data); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | return unserialize($data); |
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param array $item |
@@ -54,63 +54,63 @@ discard block |
||
54 | 54 | return (array)$cacheData; |
55 | 55 | } |
56 | 56 | |
57 | - /** |
|
58 | - * @param mixed $currentCacheData |
|
59 | - * @param mixed $cacheData |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
63 | - { |
|
64 | - /** |
|
65 | - * Se ambos forem arrays, mescle-os de forma recursiva para preservar subarrays |
|
66 | - */ |
|
67 | - if (is_array($currentCacheData) && is_array($cacheData)) { |
|
68 | - return self::mergeRecursive($currentCacheData, $cacheData); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Se $currentCacheData não for um array, inicialize-o como um array vazio |
|
73 | - */ |
|
74 | - if (!is_array($currentCacheData)) { |
|
75 | - $currentCacheData = []; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Se $cacheData não for um array, converta-o em um array |
|
80 | - */ |
|
81 | - if (!is_array($cacheData)) { |
|
82 | - $cacheData = [$cacheData]; |
|
83 | - } |
|
84 | - |
|
85 | - return array_merge($currentCacheData, $cacheData); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Mescla arrays de forma recursiva. |
|
90 | - * @param array $array1 |
|
91 | - * @param array $array2 |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - private static function mergeRecursive(array $array1, array $array2) |
|
95 | - { |
|
96 | - foreach ($array2 as $key => $value) { |
|
97 | - |
|
98 | - /** |
|
99 | - * Se a chave existe em ambos os arrays e ambos os valores são arrays, mescle recursivamente |
|
100 | - */ |
|
101 | - if (isset($array1[$key]) && is_array($array1[$key]) && is_array($value)) { |
|
102 | - $array1[$key] = self::mergeRecursive($array1[$key], $value); |
|
103 | - } else { |
|
104 | - |
|
105 | - /** |
|
106 | - * Caso contrário, sobrescreva o valor em $array1 com o valor de $array2 |
|
107 | - */ |
|
108 | - $array1[$key] = $value; |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - return $array1; |
|
113 | - } |
|
57 | + /** |
|
58 | + * @param mixed $currentCacheData |
|
59 | + * @param mixed $cacheData |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
63 | + { |
|
64 | + /** |
|
65 | + * Se ambos forem arrays, mescle-os de forma recursiva para preservar subarrays |
|
66 | + */ |
|
67 | + if (is_array($currentCacheData) && is_array($cacheData)) { |
|
68 | + return self::mergeRecursive($currentCacheData, $cacheData); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Se $currentCacheData não for um array, inicialize-o como um array vazio |
|
73 | + */ |
|
74 | + if (!is_array($currentCacheData)) { |
|
75 | + $currentCacheData = []; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Se $cacheData não for um array, converta-o em um array |
|
80 | + */ |
|
81 | + if (!is_array($cacheData)) { |
|
82 | + $cacheData = [$cacheData]; |
|
83 | + } |
|
84 | + |
|
85 | + return array_merge($currentCacheData, $cacheData); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Mescla arrays de forma recursiva. |
|
90 | + * @param array $array1 |
|
91 | + * @param array $array2 |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + private static function mergeRecursive(array $array1, array $array2) |
|
95 | + { |
|
96 | + foreach ($array2 as $key => $value) { |
|
97 | + |
|
98 | + /** |
|
99 | + * Se a chave existe em ambos os arrays e ambos os valores são arrays, mescle recursivamente |
|
100 | + */ |
|
101 | + if (isset($array1[$key]) && is_array($array1[$key]) && is_array($value)) { |
|
102 | + $array1[$key] = self::mergeRecursive($array1[$key], $value); |
|
103 | + } else { |
|
104 | + |
|
105 | + /** |
|
106 | + * Caso contrário, sobrescreva o valor em $array1 com o valor de $array2 |
|
107 | + */ |
|
108 | + $array1[$key] = $value; |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + return $array1; |
|
113 | + } |
|
114 | 114 | |
115 | 115 | } |
116 | 116 |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | /** |
16 | - * @param string $expiration |
|
17 | - * @return int |
|
18 | - */ |
|
16 | + * @param string $expiration |
|
17 | + * @return int |
|
18 | + */ |
|
19 | 19 | public static function convertExpirationToSeconds(string $expiration) |
20 | 20 | { |
21 | 21 | $units = [ |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | - * @param string|int $ttl |
|
67 | - * @param int $defaultTTL |
|
68 | - * @return mixed |
|
69 | - */ |
|
66 | + * @param string|int $ttl |
|
67 | + * @param int $defaultTTL |
|
68 | + * @return mixed |
|
69 | + */ |
|
70 | 70 | public static function ttl(string|int $ttl = null, int $defaultTTL = null) { |
71 | 71 | if ($ttl) { |
72 | 72 | $ttl = is_string($ttl) ? CacheFileHelper::convertExpirationToSeconds($ttl) : $ttl; |
@@ -76,19 +76,19 @@ discard block |
||
76 | 76 | return $ttl; |
77 | 77 | } |
78 | 78 | |
79 | - /** |
|
80 | - * @param mixed $currentCacheData |
|
81 | - * @param mixed $cacheData |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
85 | - { |
|
79 | + /** |
|
80 | + * @param mixed $currentCacheData |
|
81 | + * @param mixed $cacheData |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
85 | + { |
|
86 | 86 | if (is_array($currentCacheData) && is_array($cacheData)) { |
87 | - $mergedCacheData = array_merge($currentCacheData, $cacheData); |
|
87 | + $mergedCacheData = array_merge($currentCacheData, $cacheData); |
|
88 | 88 | } else { |
89 | - $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData); |
|
89 | + $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | return $mergedCacheData; |
93 | - } |
|
93 | + } |
|
94 | 94 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | * @param int $defaultTTL |
68 | 68 | * @return mixed |
69 | 69 | */ |
70 | - public static function ttl(string|int $ttl = null, int $defaultTTL = null) { |
|
70 | + public static function ttl(string | int $ttl = null, int $defaultTTL = null) { |
|
71 | 71 | if ($ttl) { |
72 | 72 | $ttl = is_string($ttl) ? CacheFileHelper::convertExpirationToSeconds($ttl) : $ttl; |
73 | 73 | } else { |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | - /** |
|
28 | - * @param array $options |
|
29 | - * @return array |
|
30 | - */ |
|
27 | + /** |
|
28 | + * @param array $options |
|
29 | + * @return array |
|
30 | + */ |
|
31 | 31 | public static function mergeCacheData($cacheData) |
32 | 32 | { |
33 | 33 | if (is_array($cacheData) && is_array(reset($cacheData))) { |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | return (array)$cacheData; |
41 | 41 | } |
42 | 42 | |
43 | - /** |
|
44 | - * @param mixed $currentCacheData |
|
45 | - * @param mixed $cacheData |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
49 | - { |
|
43 | + /** |
|
44 | + * @param mixed $currentCacheData |
|
45 | + * @param mixed $cacheData |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
49 | + { |
|
50 | 50 | if (is_array($currentCacheData) && is_array($cacheData)) { |
51 | - $mergedCacheData = array_merge($currentCacheData, $cacheData); |
|
51 | + $mergedCacheData = array_merge($currentCacheData, $cacheData); |
|
52 | 52 | } else { |
53 | - $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData); |
|
53 | + $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $mergedCacheData; |
57 | - } |
|
57 | + } |
|
58 | 58 | |
59 | 59 | } |
60 | 60 |
@@ -37,7 +37,7 @@ |
||
37 | 37 | */ |
38 | 38 | private static function auth() |
39 | 39 | { |
40 | - if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') { |
|
40 | + if (is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') { |
|
41 | 41 | self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']); |
42 | 42 | } |
43 | 43 | } |
@@ -14,38 +14,38 @@ |
||
14 | 14 | class RedisCacheManager |
15 | 15 | { |
16 | 16 | |
17 | - /** @var Predis\Client */ |
|
18 | - private static $redis; |
|
17 | + /** @var Predis\Client */ |
|
18 | + private static $redis; |
|
19 | 19 | |
20 | - /** @param string $namespace */ |
|
21 | - private static $namespace; |
|
20 | + /** @param string $namespace */ |
|
21 | + private static $namespace; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return Client |
|
25 | - */ |
|
26 | - public static function connect() |
|
27 | - { |
|
23 | + /** |
|
24 | + * @return Client |
|
25 | + */ |
|
26 | + public static function connect() |
|
27 | + { |
|
28 | 28 | Autoloader::register(); |
29 | 29 | self::$redis = new Client([ |
30 | - 'scheme' => 'tcp', |
|
31 | - 'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'], |
|
32 | - 'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'], |
|
33 | - 'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'], |
|
34 | - 'database' => 0 |
|
30 | + 'scheme' => 'tcp', |
|
31 | + 'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'], |
|
32 | + 'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'], |
|
33 | + 'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'], |
|
34 | + 'database' => 0 |
|
35 | 35 | ]); |
36 | 36 | self::auth(); |
37 | 37 | self::$namespace = REDIS_CONNECTION_CONFIG['REDIS_NAMESPACE'] ?? 'Cache'; |
38 | 38 | return self::$redis; |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - private static function auth() |
|
45 | - { |
|
41 | + /** |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + private static function auth() |
|
45 | + { |
|
46 | 46 | if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') { |
47 | - self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']); |
|
47 | + self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']); |
|
48 | + } |
|
48 | 49 | } |
49 | - } |
|
50 | 50 | |
51 | 51 | } |