1 | <?php |
||
16 | class CacheBuilder |
||
17 | { |
||
18 | /** |
||
19 | * @var CacheFactoryInterface |
||
20 | */ |
||
21 | private $factory; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private $caches = []; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $withExceptions = true; |
||
32 | |||
33 | /** |
||
34 | * @var LoggerInterface |
||
35 | */ |
||
36 | private $logger = null; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $logLevel = LogLevel::ALERT; |
||
42 | |||
43 | /** |
||
44 | * CacheBuilder constructor. |
||
45 | * |
||
46 | * @param CacheFactoryInterface $cacheFactory |
||
47 | 1 | */ |
|
48 | public function __construct(CacheFactoryInterface $cacheFactory = null) |
||
52 | |||
53 | /** |
||
54 | * @return $this |
||
55 | 1 | */ |
|
56 | public function withoutExceptions() |
||
62 | |||
63 | /** |
||
64 | * Sets a logger to log exceptions |
||
65 | * |
||
66 | * @param LoggerInterface $logger |
||
67 | * @param string $logLevel |
||
68 | * |
||
69 | * @return $this |
||
70 | 1 | */ |
|
71 | public function withLogging(LoggerInterface $logger, $logLevel = LogLevel::ALERT) |
||
78 | |||
79 | /** |
||
80 | * @param string $host |
||
81 | * @param int $port |
||
82 | * @param int $db |
||
83 | * @param float $timeOut |
||
84 | * |
||
85 | * @return $this |
||
86 | 1 | */ |
|
87 | public function withRedisCacheFromParams($host = '127.0.0.1', $port = 6379, $db = 0, $timeOut = 0.0) |
||
93 | |||
94 | /** |
||
95 | * @return $this |
||
96 | 1 | */ |
|
97 | public function withArrayCache() |
||
103 | |||
104 | /** |
||
105 | * @param Redis $redis |
||
106 | * |
||
107 | * @return $this |
||
108 | 1 | */ |
|
109 | public function withRedis(Redis $redis) |
||
115 | |||
116 | /** |
||
117 | * @param Cache $cache |
||
118 | * |
||
119 | * @return $this |
||
120 | 1 | */ |
|
121 | public function withCache(Cache $cache) |
||
127 | |||
128 | /** |
||
129 | * @return Cache |
||
130 | 1 | */ |
|
131 | private function buildCache() |
||
144 | |||
145 | /** |
||
146 | * @return LoggerCache |
||
147 | 1 | */ |
|
148 | public function build() |
||
154 | } |
||
155 |