1
|
|
|
<?php namespace Arcanedev\Settings; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Manager; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class SettingsManager |
7
|
|
|
* |
8
|
|
|
* @package Arcanedev\Settings |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @method mixed get(mixed $key, mixed $default = null) |
12
|
|
|
* @method bool has(string $key) |
13
|
|
|
* @method void set(string $key, mixed $value = null) |
14
|
|
|
* @method void forget(string $key) |
15
|
|
|
* @method void reset() |
16
|
|
|
* @method array all() |
17
|
|
|
* @method array save() |
18
|
|
|
*/ |
19
|
|
|
class SettingsManager extends Manager |
20
|
|
|
{ |
21
|
|
|
/* ------------------------------------------------------------------------------------------------ |
22
|
|
|
| Main Functions |
23
|
|
|
| ------------------------------------------------------------------------------------------------ |
24
|
|
|
*/ |
25
|
|
|
/** |
26
|
|
|
* Get the default driver name. |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
12 |
|
public function getDefaultDriver() |
31
|
|
|
{ |
32
|
12 |
|
return $this->getConfig('default', 'json'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/* ------------------------------------------------------------------------------------------------ |
36
|
|
|
| Driver Functions |
37
|
|
|
| ------------------------------------------------------------------------------------------------ |
38
|
|
|
*/ |
39
|
|
|
/** |
40
|
|
|
* Create the Json driver store. |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
9 |
|
public function createJsonDriver() |
45
|
|
|
{ |
46
|
9 |
|
return new Stores\JsonStore( |
47
|
9 |
|
$this->app['files'], |
48
|
9 |
|
$this->getConfig('stores.json.path') |
49
|
9 |
|
); |
50
|
3 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Create the Database driver store. |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
3 |
|
public function createDatabaseDriver() |
58
|
|
|
{ |
59
|
3 |
|
return new Stores\DatabaseStore( |
60
|
3 |
|
$this->getConfig('stores.database.connection'), |
61
|
3 |
|
$this->getConfig('stores.database.table') |
62
|
3 |
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Create the Memory driver store. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
3 |
|
public function createMemoryDriver() |
71
|
|
|
{ |
72
|
3 |
|
return new Stores\MemoryStore; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Create the Array driver store. |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
3 |
|
public function createArrayDriver() |
81
|
|
|
{ |
82
|
3 |
|
return new Stores\ArrayStore; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/* ------------------------------------------------------------------------------------------------ |
86
|
|
|
| Other Functions |
87
|
|
|
| ------------------------------------------------------------------------------------------------ |
88
|
|
|
*/ |
89
|
|
|
/** |
90
|
|
|
* Get config. |
91
|
|
|
* |
92
|
|
|
* @param string $key |
93
|
|
|
* @param mixed|null $default |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
12 |
|
protected function getConfig($key, $default = null) |
98
|
|
|
{ |
99
|
|
|
/** @var \Illuminate\Config\Repository $config */ |
100
|
12 |
|
$config = $this->app['config']; |
101
|
|
|
|
102
|
12 |
|
return $config->get("settings.$key", $default); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|