1 | <?php |
||
16 | class Repository |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * The instance of the config. |
||
21 | * |
||
22 | * @var \Longman\LaravelMultiLang\Config |
||
23 | */ |
||
24 | protected $config; |
||
25 | |||
26 | /** |
||
27 | * The instance of the cache. |
||
28 | * |
||
29 | * @var \Illuminate\Cache\CacheManager |
||
30 | */ |
||
31 | protected $cache; |
||
32 | |||
33 | /** |
||
34 | * The instance of the database. |
||
35 | * |
||
36 | * @var \Illuminate\Database\DatabaseManager |
||
37 | */ |
||
38 | protected $db; |
||
39 | |||
40 | /** |
||
41 | * Create a new MultiLang instance. |
||
42 | * |
||
43 | * @param \Longman\LaravelMultiLang\Config $config |
||
44 | * @param \Illuminate\Cache\CacheManager $cache |
||
45 | * @param \Illuminate\Database\DatabaseManager $db |
||
46 | */ |
||
47 | 30 | public function __construct(Config $config, Cache $cache, Database $db) |
|
53 | |||
54 | /** |
||
55 | * Get cache key name based on lang and scope |
||
56 | * |
||
57 | * @param string $lang |
||
58 | * @param string $scope |
||
59 | * @return string |
||
60 | */ |
||
61 | 6 | public function getCacheName($lang, $scope = null) |
|
70 | |||
71 | /** |
||
72 | * Load texts from database storage |
||
73 | * |
||
74 | * @param string $lang |
||
75 | * @param string $scope |
||
76 | * @return array |
||
77 | */ |
||
78 | 20 | public function loadFromDatabase($lang, $scope = null) |
|
101 | |||
102 | /** |
||
103 | * Load all texts from database storage |
||
104 | * |
||
105 | * @param string $lang |
||
106 | * @param string $scope |
||
107 | * @return array |
||
108 | */ |
||
109 | public function loadAllFromDatabase($lang = null, $scope = null) |
||
133 | |||
134 | /** |
||
135 | * Load texts from cache storage |
||
136 | * |
||
137 | * @param string $lang |
||
138 | * @param string $scope |
||
139 | * @return mixed |
||
140 | */ |
||
141 | 2 | public function loadFromCache($lang, $scope = null) |
|
147 | |||
148 | /** |
||
149 | * Store texts in cache |
||
150 | * |
||
151 | * @param string $lang |
||
152 | * @param array $texts |
||
153 | * @param string $scope |
||
154 | * @return $this |
||
155 | */ |
||
156 | 4 | public function storeInCache($lang, array $texts, $scope = null) |
|
162 | |||
163 | /** |
||
164 | * Check if we must load texts from cache |
||
165 | * |
||
166 | * @param string $lang |
||
167 | * @param string $scope |
||
168 | * @return bool |
||
169 | */ |
||
170 | 4 | public function existsInCache($lang, $scope = null) |
|
174 | |||
175 | /** |
||
176 | * Get a database connection instance. |
||
177 | * |
||
178 | * @return \Illuminate\Database\Connection |
||
179 | */ |
||
180 | 20 | protected function getDb() |
|
189 | |||
190 | /** |
||
191 | * Get a cache driver instance. |
||
192 | * |
||
193 | * @return \Illuminate\Contracts\Cache\Repository |
||
194 | */ |
||
195 | 4 | protected function getCache() |
|
204 | |||
205 | /** |
||
206 | * Save missing texts in database |
||
207 | * |
||
208 | * @param array $texts |
||
209 | * @param string $scope |
||
210 | * @return bool |
||
211 | */ |
||
212 | 4 | public function save(array $texts, $scope = null) |
|
251 | |||
252 | /** |
||
253 | * Get texts table name |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | 21 | public function getTableName() |
|
263 | } |
||
264 |