1 | <?php |
||
19 | class Config implements Repository |
||
20 | { |
||
21 | /** |
||
22 | * @var string The delimiter used in the array keys to specify the heirachy |
||
23 | */ |
||
24 | const KEY_DELIMITER = '.'; |
||
25 | |||
26 | /** |
||
27 | * @var string the pattern to match array keys |
||
28 | */ |
||
29 | const ARRAY_PATTERN = "/\[([0-9]+)\]$/"; |
||
30 | |||
31 | /** |
||
32 | * The configuration data |
||
33 | * @var array |
||
34 | */ |
||
35 | private $data; |
||
36 | |||
37 | public $modifiers; |
||
38 | |||
39 | /** |
||
40 | * @var \Illuminate\Support\Arr |
||
41 | */ |
||
42 | private $arrHelper; |
||
43 | |||
44 | private $storage; |
||
45 | |||
46 | /** |
||
47 | * constructor |
||
48 | * The initial data |
||
49 | * |
||
50 | * @param array|StorageInterface $data the flattened data |
||
51 | * @param Arr|null $arrHelper the array helper |
||
52 | */ |
||
53 | public function __construct($data = [], Arr $arrHelper = null) |
||
72 | |||
73 | /** |
||
74 | * Set the array helper |
||
75 | * |
||
76 | * @param Arr|null $arrHelper |
||
77 | */ |
||
78 | private function setArrHelper(Arr $arrHelper = null) |
||
85 | |||
86 | /** |
||
87 | * Reduce the configuration to a simple key/value array, despite the |
||
88 | * heirachy of information |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | public function flatten() |
||
96 | |||
97 | /** |
||
98 | * Create/Update a configuration value |
||
99 | * |
||
100 | * @param string $key |
||
101 | * @param mixed $value |
||
102 | */ |
||
103 | public function set($key, $value = null) |
||
120 | |||
121 | /** |
||
122 | * Get the configuration value based on it's key |
||
123 | * |
||
124 | * @param string $key |
||
125 | * @param mixed $default |
||
126 | * @return mixed |
||
127 | */ |
||
128 | public function get($key, $default = null) |
||
135 | |||
136 | /*** |
||
137 | * Get all of the configuration data in it's hierarchical state |
||
138 | */ |
||
139 | public function all() |
||
143 | |||
144 | /** |
||
145 | * Remove an item from the configuration |
||
146 | * |
||
147 | * @param string $key |
||
148 | * @return boolean |
||
149 | */ |
||
150 | public function forget($key) |
||
158 | |||
159 | /** |
||
160 | * Clear all of the settings from the configuration |
||
161 | * |
||
162 | * @return boolean |
||
163 | */ |
||
164 | public function clear() |
||
173 | |||
174 | /** |
||
175 | * Check if a configuration setting exists |
||
176 | * |
||
177 | * @param string $key |
||
178 | * @return boolean |
||
179 | */ |
||
180 | public function has($key) |
||
184 | |||
185 | /** |
||
186 | * Prepend a value onto the key. |
||
187 | * |
||
188 | * If that existing key is not an array it will be converted into an array |
||
189 | * and the the value will be the first element of the array |
||
190 | * |
||
191 | * @param string $key |
||
192 | * @param mixed $value |
||
193 | * @return void |
||
194 | */ |
||
195 | public function prepend($key, $value) |
||
201 | |||
202 | /** |
||
203 | * Push a value onto the key |
||
204 | * |
||
205 | * If that existing key is not an array it will be converted into an array |
||
206 | * and the the value will be the first element of the array |
||
207 | * |
||
208 | * @param string $key |
||
209 | * @param mixed $value |
||
210 | * @return void |
||
211 | */ |
||
212 | public function push($key, $value) |
||
218 | |||
219 | /** |
||
220 | * Get the value, as an array |
||
221 | * |
||
222 | * @param string $key |
||
223 | * @return array any existing value will be converted to the first element |
||
224 | * of the array |
||
225 | */ |
||
226 | private function getAsArray($key) |
||
234 | |||
235 | /** |
||
236 | * Converts the flat key/value from the storage engine |
||
237 | * to a heirachy structure based on the key sytax |
||
238 | * |
||
239 | * @param array $data |
||
240 | * @return array |
||
241 | */ |
||
242 | private function dataDecode($data) |
||
256 | |||
257 | /** |
||
258 | * unpack the keys that are structured for arrays so that they no |
||
259 | * longer have the [] syntax at the end. Rather they're now a proper |
||
260 | * array. |
||
261 | * |
||
262 | * @param array $data [description] |
||
263 | * @return array |
||
264 | */ |
||
265 | private function unpackArray($data) |
||
280 | |||
281 | /** |
||
282 | * Flatten a multi-dimensional array into a linear key/value list |
||
283 | * |
||
284 | * @param array $data |
||
285 | * @param string|null $prefix |
||
286 | * @return array |
||
287 | */ |
||
288 | private function dataEncode($data, $prefix = null) |
||
303 | |||
304 | /** |
||
305 | * Encode the array of values against the provided key |
||
306 | * |
||
307 | * @param string $key |
||
308 | * @param array $value either an associative or keyed array |
||
309 | * @param string|null $prefix |
||
310 | * @return array |
||
311 | */ |
||
312 | private function encodeArray($key, array $value, $prefix = null) |
||
323 | |||
324 | /** |
||
325 | * Validate the value as safe for this object |
||
326 | * |
||
327 | * @param mixed $value the value to test |
||
328 | * @return boolean |
||
329 | */ |
||
330 | private function isValidValue($value) |
||
340 | } |
||
341 |