1 | <?php namespace Cornford\Setter; |
||
8 | abstract class SettingBase { |
||
9 | |||
10 | const LOCATION_DATABASE = 'database'; |
||
11 | const LOCATION_CACHE = 'cache'; |
||
12 | |||
13 | const CACHE_TAG = 'setter::'; |
||
14 | |||
15 | /** |
||
16 | * Database |
||
17 | * |
||
18 | * @var \Illuminate\Database\DatabaseManager |
||
19 | */ |
||
20 | protected $database; |
||
21 | |||
22 | /** |
||
23 | * Config |
||
24 | * |
||
25 | * @var \Illuminate\Config\Repository |
||
26 | */ |
||
27 | protected $config; |
||
28 | |||
29 | /** |
||
30 | * Cache |
||
31 | * |
||
32 | * @var \Illuminate\Cache\Repository |
||
33 | */ |
||
34 | protected $cache; |
||
35 | |||
36 | /** |
||
37 | * Cache |
||
38 | * |
||
39 | * @var integer|datetime|boolean |
||
40 | */ |
||
41 | protected $expiry = true; |
||
42 | |||
43 | /** |
||
44 | * Construct Setter |
||
45 | * |
||
46 | * @param Query $database |
||
47 | * @param Repository $config |
||
48 | * @param Cache $cache |
||
49 | */ |
||
50 | public function __construct(Query $database, Repository $config, Cache $cache) |
||
56 | |||
57 | /** |
||
58 | * Return a key with an attached cache tag |
||
59 | * |
||
60 | * @param string $key |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | protected function attachTag($key) |
||
68 | |||
69 | /** |
||
70 | * Check a setting exists in cache |
||
71 | * |
||
72 | * @param string $key |
||
73 | * |
||
74 | * @return boolean |
||
75 | */ |
||
76 | public function cacheHas($key) |
||
80 | |||
81 | |||
82 | /** |
||
83 | * Forget a cached setting by key |
||
84 | * |
||
85 | * @param string $key |
||
86 | * |
||
87 | * @return boolean |
||
88 | */ |
||
89 | public function cacheForget($key) |
||
96 | |||
97 | /** |
||
98 | * Clear all cached settings |
||
99 | * |
||
100 | * @return boolean |
||
101 | */ |
||
102 | public function cacheClear() |
||
109 | |||
110 | /** |
||
111 | * Check a setting exists in config |
||
112 | * |
||
113 | * @param string $key |
||
114 | * |
||
115 | * @return boolean |
||
116 | */ |
||
117 | public function configHas($key) |
||
121 | |||
122 | /** |
||
123 | * Arrange results into an associative array |
||
124 | * |
||
125 | * @param array $results |
||
126 | * @param string $key |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | protected function arrangeResults($results, $key = null) |
||
147 | |||
148 | /** |
||
149 | * Return result values |
||
150 | * |
||
151 | * @param array $results |
||
152 | * @param string $key |
||
153 | * |
||
154 | * @return string|array |
||
155 | */ |
||
156 | protected function returnResults($results = array(), $key) |
||
173 | |||
174 | /** |
||
175 | * Combine result values from the database and configuration |
||
176 | * |
||
177 | * @param array $results |
||
178 | * @param string $key |
||
179 | * |
||
180 | * @return array |
||
181 | */ |
||
182 | protected function combineResults(array $results = array(), $key) |
||
192 | |||
193 | /** |
||
194 | * Re-cache item and its parents |
||
195 | * |
||
196 | * @param string $value |
||
197 | * @param string $key |
||
198 | * |
||
199 | * @return void |
||
200 | */ |
||
201 | protected function recacheItem($value, $key) |
||
221 | |||
222 | /** |
||
223 | * Return cache values |
||
224 | * |
||
225 | * @param string $key |
||
226 | * |
||
227 | * @return string|array |
||
228 | */ |
||
229 | protected function returnCache($key) |
||
235 | |||
236 | /** |
||
237 | * Return config values |
||
238 | * |
||
239 | * @param string $key |
||
240 | * |
||
241 | * @return string|array |
||
242 | */ |
||
243 | protected function returnConfig($key) |
||
249 | |||
250 | /** |
||
251 | * Is the string Json encoded. |
||
252 | * |
||
253 | * @param string $string |
||
254 | * @return boolean |
||
255 | */ |
||
256 | protected function isJson($string) |
||
266 | |||
267 | /** |
||
268 | * Decode a Json item. |
||
269 | * |
||
270 | * @param mixed $value |
||
271 | * |
||
272 | * @return mixed |
||
273 | */ |
||
274 | protected function decodeJson($value) |
||
282 | |||
283 | } |
||
284 |