Skip to content

Commit

Permalink
include fallback during data load #79
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Feb 8, 2021
1 parent 5731c99 commit 44a193f
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Contracts/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ abstract class Driver
*/
protected $loaded = false;

/**
* Include and merge with fallbacks
*
* @var bool
*/
protected $with_fallback = true;

/**
* Excludes fallback data
*/
public function withoutFallback()
{
$this->with_fallback = false;

return $this;
}

/**
* Get a specific key from the settings data.
*
Expand All @@ -44,7 +61,7 @@ public function get($key, $default = null)

$this->load();

return Arr::get($this->data, $key, $this->getFallback($key, $default));
return Arr::get($this->data, $key, $default);
}

/**
Expand Down Expand Up @@ -199,7 +216,10 @@ public function load($force = false)
return;
}

$this->data = $this->readData();
$fallback_data = $this->with_fallback ? config('setting.fallback') : [];
$driver_data = $this->readData();

$this->data = array_merge((array) $fallback_data, (array) $driver_data);
$this->loaded = true;
}

Expand Down

0 comments on commit 44a193f

Please sign in to comment.