1 | <?php |
||
10 | class DatabaseRepository extends AbstractRepository |
||
11 | { |
||
12 | /** |
||
13 | * $original. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $original = []; |
||
18 | |||
19 | /** |
||
20 | * $key. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $key = 'configs'; |
||
25 | |||
26 | /** |
||
27 | * $repository. |
||
28 | * |
||
29 | * @var \Recca0120\Config\Config |
||
30 | */ |
||
31 | protected $model; |
||
32 | |||
33 | /** |
||
34 | * $files. |
||
35 | * |
||
36 | * @var \Illuminate\Filesystem\Filesystem |
||
37 | */ |
||
38 | protected $files; |
||
39 | |||
40 | /** |
||
41 | * $config. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $config; |
||
46 | |||
47 | /** |
||
48 | * __construct. |
||
49 | * |
||
50 | * @param \Illuminate\Contracts\Config\Repository $repository |
||
51 | * @param \Recca0120\Config\Config $model |
||
52 | * @param array $config |
||
53 | */ |
||
54 | 2 | public function __construct(Repository $repository, Config $model, Filesystem $files, $config = []) |
|
55 | { |
||
56 | 2 | parent::__construct($repository); |
|
57 | |||
58 | 2 | $this->original = $repository->all(); |
|
59 | 2 | $this->model = $model; |
|
60 | 2 | $this->files = $files; |
|
61 | 2 | $this->config = $config; |
|
62 | |||
63 | 2 | foreach (Arr::dot($this->load()) as $key => $value) { |
|
64 | $repository->set($key, $value); |
||
65 | 1 | } |
|
66 | 1 | } |
|
67 | |||
68 | /** |
||
69 | * Set a given configuration value. |
||
70 | * |
||
71 | * @param array|string $key |
||
72 | * @param mixed $value |
||
73 | */ |
||
74 | 1 | public function set($key, $value = null) |
|
75 | { |
||
76 | 1 | parent::set($key, $value); |
|
77 | 1 | $this->store(); |
|
78 | 1 | } |
|
79 | |||
80 | /** |
||
81 | * Unset a configuration option. |
||
82 | * |
||
83 | * @param string $key |
||
84 | */ |
||
85 | 1 | public function offsetUnset($key) |
|
86 | { |
||
87 | 1 | parent::offsetUnset($key); |
|
88 | 1 | $this->store(); |
|
89 | 1 | } |
|
90 | |||
91 | /** |
||
92 | * getStorageFile. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 2 | public function getStorageFile() |
|
97 | { |
||
98 | 2 | return Arr::get($this->config, 'path').'config.json'; |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * cloneModel. |
||
103 | * |
||
104 | * @return \Recca0120\Config\Config |
||
105 | */ |
||
106 | 2 | protected function cloneModel() |
|
110 | |||
111 | /** |
||
112 | * getModel. |
||
113 | * |
||
114 | * @return \Recca0120\Config\Config |
||
115 | */ |
||
116 | 2 | protected function getModel() |
|
122 | |||
123 | /** |
||
124 | * storeToFile. |
||
125 | * |
||
126 | * @param mixed $data |
||
127 | * @return $this |
||
128 | */ |
||
129 | 2 | protected function storeToFile($data) |
|
142 | |||
143 | /** |
||
144 | * load. |
||
145 | * |
||
146 | * @return array |
||
147 | */ |
||
148 | 2 | protected function load() |
|
159 | |||
160 | /** |
||
161 | * store. |
||
162 | */ |
||
163 | 1 | protected function store() |
|
177 | |||
178 | /** |
||
179 | * arrayDiffAssocRecursive. |
||
180 | * |
||
181 | * @param array $array1 |
||
182 | * @param array $array2 |
||
183 | * @return array |
||
184 | */ |
||
185 | 1 | protected function arrayDiffAssocRecursive($array1, $array2) |
|
205 | |||
206 | /** |
||
207 | * protectedKeys. |
||
208 | * |
||
209 | * @param array $data |
||
210 | * @return array |
||
211 | */ |
||
212 | 1 | protected function protectedKeys($data) |
|
220 | } |
||
221 |