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