1 | <?php namespace Arcanedev\Settings\Bases; |
||
11 | abstract class Store |
||
12 | { |
||
13 | /* ------------------------------------------------------------------------------------------------ |
||
14 | | Properties |
||
15 | | ------------------------------------------------------------------------------------------------ |
||
16 | */ |
||
17 | /** |
||
18 | * The settings data. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $data = []; |
||
23 | |||
24 | /** |
||
25 | * Whether the store has changed since it was last loaded. |
||
26 | * |
||
27 | * @var bool |
||
28 | */ |
||
29 | protected $unsaved = false; |
||
30 | |||
31 | /** |
||
32 | * Whether the settings data are loaded. |
||
33 | * |
||
34 | * @var bool |
||
35 | */ |
||
36 | protected $loaded = false; |
||
37 | |||
38 | /* ------------------------------------------------------------------------------------------------ |
||
39 | | Main Functions |
||
40 | | ------------------------------------------------------------------------------------------------ |
||
41 | */ |
||
42 | /** |
||
43 | * Get a specific key from the settings data. |
||
44 | * |
||
45 | * @param string|array $key |
||
46 | * @param mixed $default Optional default value. |
||
47 | * |
||
48 | * @return mixed |
||
49 | */ |
||
50 | 15 | public function get($key, $default = null) |
|
56 | |||
57 | /** |
||
58 | * Determine if a key exists in the settings data. |
||
59 | * |
||
60 | * @param string $key |
||
61 | * |
||
62 | * @return boolean |
||
63 | */ |
||
64 | 18 | public function has($key) |
|
70 | |||
71 | /** |
||
72 | * Set a specific key to a value in the settings data. |
||
73 | * |
||
74 | * @param string|array $key Key string or associative array of key => value |
||
75 | * @param mixed $value Optional only if the first argument is an array |
||
76 | */ |
||
77 | 48 | public function set($key, $value = null) |
|
90 | |||
91 | /** |
||
92 | * Unset a key in the settings data. |
||
93 | * |
||
94 | * @param string $key |
||
95 | */ |
||
96 | 18 | public function forget($key) |
|
104 | |||
105 | /** |
||
106 | * Unset all keys in the settings data. |
||
107 | */ |
||
108 | 9 | public function reset() |
|
113 | |||
114 | /** |
||
115 | * Get all settings data. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | 45 | public function all() |
|
125 | |||
126 | /** |
||
127 | * Save any changes done to the settings data. |
||
128 | */ |
||
129 | 15 | public function save() |
|
138 | |||
139 | /* ------------------------------------------------------------------------------------------------ |
||
140 | | Other Functions |
||
141 | | ------------------------------------------------------------------------------------------------ |
||
142 | */ |
||
143 | /** |
||
144 | * Check if the settings data has been loaded. |
||
145 | */ |
||
146 | 66 | protected function checkLoaded() |
|
153 | |||
154 | /** |
||
155 | * Read the data from the store. |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | abstract protected function read(); |
||
160 | |||
161 | /** |
||
162 | * Write the data into the store. |
||
163 | * |
||
164 | * @param array $data |
||
165 | */ |
||
166 | abstract protected function write(array $data); |
||
167 | } |
||
168 |