| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\StorageDrivers\Local; |
| 4 |
|
| 5 |
use FluentCart\Framework\Support\Arr; |
| 6 |
|
| 7 |
class LocalSettings |
| 8 |
{ |
| 9 |
|
| 10 |
protected $settings; |
| 11 |
|
| 12 |
protected $driverHandler = 'fluent_cart_storage_settings_local'; |
| 13 |
|
| 14 |
static ?array $cachedSettings = null; |
| 15 |
|
| 16 |
public function __construct() |
| 17 |
{ |
| 18 |
if (self::$cachedSettings) { |
| 19 |
$this->settings = self::$cachedSettings; |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
$settings = fluent_cart_get_option($this->driverHandler, []); |
| 24 |
$this->settings = wp_parse_args($settings, static::getDefaults()); |
| 25 |
self::$cachedSettings = $this->settings; |
| 26 |
} |
| 27 |
|
| 28 |
public static function getDefaults() |
| 29 |
{ |
| 30 |
return [ |
| 31 |
'is_active' => 'yes', |
| 32 |
]; |
| 33 |
} |
| 34 |
|
| 35 |
public function isActive() |
| 36 |
{ |
| 37 |
$settings = $this->get(); |
| 38 |
|
| 39 |
return Arr::get($settings, 'is_active') === 'yes'; |
| 40 |
} |
| 41 |
|
| 42 |
public function get($key = '') |
| 43 |
{ |
| 44 |
return $this->settings; |
| 45 |
} |
| 46 |
} |