1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silviooosilva\CacheerPhp\Helpers; |
4
|
|
|
|
5
|
|
|
use Silviooosilva\CacheerPhp\Cacheer; |
6
|
|
|
use Silviooosilva\CacheerPhp\CacheStore\ArrayCacheStore; |
7
|
|
|
use Silviooosilva\CacheerPhp\CacheStore\FileCacheStore; |
8
|
|
|
use Silviooosilva\CacheerPhp\CacheStore\RedisCacheStore; |
9
|
|
|
use Silviooosilva\CacheerPhp\Core\Connect; |
10
|
|
|
use Silviooosilva\CacheerPhp\Exceptions\ConnectionException; |
11
|
|
|
use Silviooosilva\CacheerPhp\Utils\CacheDriver; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class CacheConfig |
15
|
|
|
* @author Sílvio Silva <https://github.com/silviooosilva> |
16
|
|
|
* @package Silviooosilva\CacheerPhp |
17
|
|
|
*/ |
18
|
|
|
class CacheConfig |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Cacheer |
23
|
|
|
*/ |
24
|
|
|
protected Cacheer $cacheer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* CacheConfig constructor. |
28
|
|
|
* |
29
|
|
|
* @param Cacheer $cacheer |
30
|
|
|
*/ |
31
|
|
|
public function __construct(Cacheer $cacheer) |
32
|
|
|
{ |
33
|
|
|
$this->cacheer = $cacheer; |
34
|
|
|
$this->setTimeZone(date_default_timezone_get()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Sets the default timezone for the application. |
39
|
|
|
* |
40
|
|
|
* @param string $timezone |
41
|
|
|
* @return $this |
42
|
|
|
*/ |
43
|
|
|
public function setTimeZone(string $timezone): CacheConfig |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* Make sure the provided timezone is valid |
47
|
|
|
* |
48
|
|
|
* https://www.php.net/manual/en/timezones.php |
49
|
|
|
* */ |
50
|
|
|
|
51
|
|
|
if (in_array($timezone, timezone_identifiers_list())) { |
|
|
|
|
52
|
|
|
date_default_timezone_set($timezone); |
53
|
|
|
} |
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Sets the cache driver for the application. |
59
|
|
|
* |
60
|
|
|
* @return CacheDriver |
61
|
|
|
*/ |
62
|
|
|
public function setDriver(): CacheDriver |
63
|
|
|
{ |
64
|
|
|
return new CacheDriver($this->cacheer); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Sets the logger path for the cache driver. |
69
|
|
|
* |
70
|
|
|
* @param string $path |
71
|
|
|
* @return Cacheer |
72
|
|
|
*/ |
73
|
|
|
public function setLoggerPath(string $path): Cacheer |
74
|
|
|
{ |
75
|
|
|
|
76
|
|
|
$cacheDriver = $this->setDriver(); |
77
|
|
|
$cacheDriver->logPath = $path; |
78
|
|
|
|
79
|
|
|
$cacheDriverInstance = $this->cacheer->cacheStore; |
80
|
|
|
|
81
|
|
|
return match (get_class($cacheDriverInstance)) { |
82
|
|
|
FileCacheStore::class => $cacheDriver->useFileDriver(), |
83
|
|
|
RedisCacheStore::class => $cacheDriver->useRedisDriver(), |
84
|
|
|
ArrayCacheStore::class => $cacheDriver->useArrayDriver(), |
85
|
|
|
default => $cacheDriver->useDatabaseDriver(), |
86
|
|
|
}; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Sets the database connection type for the application. |
91
|
|
|
* |
92
|
|
|
* @param string $driver |
93
|
|
|
* @return void |
94
|
|
|
* @throws ConnectionException |
95
|
|
|
*/ |
96
|
|
|
public function setDatabaseConnection(string $driver): void |
97
|
|
|
{ |
98
|
|
|
Connect::setConnection($driver); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Sets up the Cacheer instance with the provided options. |
103
|
|
|
* |
104
|
|
|
* @param array $options |
105
|
|
|
* @return void |
106
|
|
|
*/ |
107
|
|
|
public function setUp(array $options): void |
108
|
|
|
{ |
109
|
|
|
$this->cacheer->options = $options; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Gets the options for the Cacheer instance. |
114
|
|
|
* |
115
|
|
|
* @return array |
116
|
|
|
*/ |
117
|
|
|
public function getOptions(): array |
118
|
|
|
{ |
119
|
|
|
return $this->cacheer->options; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.