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\DatabaseCacheStore; |
8
|
|
|
use Silviooosilva\CacheerPhp\CacheStore\FileCacheStore; |
9
|
|
|
use Silviooosilva\CacheerPhp\CacheStore\RedisCacheStore; |
10
|
|
|
use Silviooosilva\CacheerPhp\Core\Connect; |
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; |
25
|
|
|
|
26
|
|
|
public function __construct(Cacheer $cacheer) |
27
|
|
|
{ |
28
|
|
|
$this->cacheer = $cacheer; |
29
|
|
|
$this->setTimeZone(date_default_timezone_get()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $timezone |
34
|
|
|
* @return $this |
35
|
|
|
*/ |
36
|
|
|
public function setTimeZone($timezone) |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Certifique-se de que o timezone fornecido é válido * |
40
|
|
|
* https://www.php.net/manual/en/timezones.php |
41
|
|
|
* */ |
42
|
|
|
|
43
|
|
|
if (in_array($timezone, timezone_identifiers_list())) { |
|
|
|
|
44
|
|
|
date_default_timezone_set($timezone); |
45
|
|
|
} |
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return CacheDriver |
51
|
|
|
*/ |
52
|
|
|
public function setDriver() |
53
|
|
|
{ |
54
|
|
|
return new CacheDriver($this->cacheer); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $path |
59
|
|
|
* @return mixed |
60
|
|
|
*/ |
61
|
|
|
public function setLoggerPath(string $path) |
62
|
|
|
{ |
63
|
|
|
|
64
|
|
|
$cacheDriver = $this->setDriver(); |
65
|
|
|
$cacheDriver->logPath = $path; |
66
|
|
|
|
67
|
|
|
$cacheDriverInstance = $this->cacheer->cacheStore; |
68
|
|
|
|
69
|
|
|
return match (get_class($cacheDriverInstance)) { |
70
|
|
|
FileCacheStore::class => $cacheDriver->useFileDriver(), |
71
|
|
|
RedisCacheStore::class => $cacheDriver->useRedisDriver(), |
72
|
|
|
ArrayCacheStore::class => $cacheDriver->useArrayDriver(), |
73
|
|
|
DatabaseCacheStore::class => $cacheDriver->useDatabaseDriver(), |
74
|
|
|
default => $cacheDriver->useDatabaseDriver(), |
75
|
|
|
}; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $driver |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public function setDatabaseConnection(string $driver) |
83
|
|
|
{ |
84
|
|
|
Connect::setConnection($driver); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.