Skip to content

Commit 44a193f

Browse files
committed
include fallback during data load #79
1 parent 5731c99 commit 44a193f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/Contracts/Driver.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ abstract class Driver
2828
*/
2929
protected $loaded = false;
3030

31+
/**
32+
* Include and merge with fallbacks
33+
*
34+
* @var bool
35+
*/
36+
protected $with_fallback = true;
37+
38+
/**
39+
* Excludes fallback data
40+
*/
41+
public function withoutFallback()
42+
{
43+
$this->with_fallback = false;
44+
45+
return $this;
46+
}
47+
3148
/**
3249
* Get a specific key from the settings data.
3350
*
@@ -44,7 +61,7 @@ public function get($key, $default = null)
4461

4562
$this->load();
4663

47-
return Arr::get($this->data, $key, $this->getFallback($key, $default));
64+
return Arr::get($this->data, $key, $default);
4865
}
4966

5067
/**
@@ -199,7 +216,10 @@ public function load($force = false)
199216
return;
200217
}
201218

202-
$this->data = $this->readData();
219+
$fallback_data = $this->with_fallback ? config('setting.fallback') : [];
220+
$driver_data = $this->readData();
221+
222+
$this->data = array_merge((array) $fallback_data, (array) $driver_data);
203223
$this->loaded = true;
204224
}
205225

0 commit comments

Comments
 (0)