You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
<?php
|
|
|
|
namespace App\Domains\System\Queries;
|
|
|
|
use App\Domains\System\Enums\SystemSettingKey;
|
|
use App\Domains\System\Models\SystemSettings;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class GetSystemSettings
|
|
{
|
|
private ?array $settings = null;
|
|
|
|
public function get(SystemSettingKey $setting): ?string
|
|
{
|
|
return $this->fetch()[$setting->value] ?? $setting->default();
|
|
}
|
|
|
|
public function fetch(): array
|
|
{
|
|
if ($this->settings !== null) {
|
|
return $this->settings;
|
|
}
|
|
|
|
$this->settings = Cache::rememberForever('system_settings', function () {
|
|
$settings = SystemSettings::pluck('value', 'key')->toArray();
|
|
$finalSettings = [];
|
|
foreach (SystemSettingKey::cases() as $key) {
|
|
$finalSettings[$key->value] = $settings[$key->value] ?? $key->default();
|
|
}
|
|
|
|
return $finalSettings;
|
|
});
|
|
|
|
return $this->settings;
|
|
}
|
|
|
|
/**
|
|
* Clears the local memory. Crucial for long-running processes like Laravel Octane.
|
|
*/
|
|
public function flushMemory(): void
|
|
{
|
|
$this->settings = null;
|
|
}
|
|
}
|
|
|