1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EasyDictionary; |
6
|
|
|
|
7
|
|
|
use EasyDictionary\DataProvider\Simple as SimpleDataProvider; |
8
|
|
|
use EasyDictionary\Dictionary\Simple as SimpleDictionary; |
9
|
|
|
use EasyDictionary\Interfaces\ConfigInterface; |
10
|
|
|
use Psr\SimpleCache\CacheInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class BasicConfig |
14
|
|
|
* |
15
|
|
|
* @package EasyDictionary\Dictionary |
16
|
|
|
*/ |
|
|
|
|
17
|
|
|
class BasicConfig implements ConfigInterface |
18
|
|
|
{ |
19
|
|
|
protected $defaultDataProviderClass = SimpleDataProvider::class; |
20
|
|
|
protected $defaultDictionaryClass = SimpleDictionary::class; |
21
|
|
|
protected $dictionaryConfig = []; |
22
|
|
|
protected $defaultView = null; |
23
|
|
|
protected $caches = []; |
24
|
|
|
|
25
|
|
|
/** |
|
|
|
|
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
public function getDefaultDataProviderClass(): string |
29
|
|
|
{ |
30
|
|
|
return $this->defaultDataProviderClass; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
|
|
|
|
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
public function getDefaultDictionaryClass(): string |
37
|
|
|
{ |
38
|
|
|
return $this->defaultDictionaryClass; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
|
|
|
|
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function getDictionaryConfig(): array |
45
|
|
|
{ |
46
|
|
|
return $this->dictionaryConfig; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
|
|
|
|
50
|
|
|
* @param array $dictionaryConfig |
|
|
|
|
51
|
|
|
* @return $this |
|
|
|
|
52
|
|
|
*/ |
53
|
|
|
public function setDictionaryConfig(array $dictionaryConfig) |
54
|
|
|
{ |
55
|
|
|
$this->dictionaryConfig = $dictionaryConfig; |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
|
|
|
|
61
|
|
|
* @return callable |
62
|
|
|
*/ |
63
|
|
|
public function getDefaultView(): ?callable |
64
|
|
|
{ |
65
|
|
|
return $this->defaultView; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
|
|
|
|
69
|
|
|
* @param callable $view |
|
|
|
|
70
|
|
|
* @return $this |
|
|
|
|
71
|
|
|
*/ |
72
|
|
|
public function setDefaultView(callable $view) |
73
|
|
|
{ |
74
|
|
|
$this->defaultView = $view; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
|
|
|
|
80
|
|
|
* @param string $name |
|
|
|
|
81
|
|
|
* @return null|CacheInterface |
|
|
|
|
82
|
|
|
*/ |
83
|
|
|
public function getCache(string $name): ?CacheInterface |
84
|
|
|
{ |
85
|
|
|
return $this->caches[$name] ?? null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
|
|
|
|
89
|
|
|
* @param CacheInterface $cache |
|
|
|
|
90
|
|
|
* @param string $name |
|
|
|
|
91
|
|
|
* @return $this |
|
|
|
|
92
|
|
|
*/ |
93
|
|
|
public function addCache(CacheInterface $cache, string $name) |
94
|
|
|
{ |
95
|
|
|
$this->caches[$name] = $cache; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|