You've already forked Epicnabbo-Catalogus-Updated-Daily
🆙 More fixes 🆙
This commit is contained in:
@@ -10,46 +10,49 @@ use Throwable;
|
||||
|
||||
class SettingsService
|
||||
{
|
||||
public private(set) ?Collection $settings;
|
||||
/** @var Collection<string, string> */
|
||||
public private(set) Collection $settings;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
$this->settings = Cache::remember(
|
||||
key: 'website_settings',
|
||||
ttl: now()->addMinutes(5),
|
||||
callback: fn () => Schema::hasTable('website_settings')
|
||||
? WebsiteSetting::all()->pluck('value', 'key')
|
||||
: collect()
|
||||
);
|
||||
} catch (Throwable) {
|
||||
$this->settings = collect();
|
||||
}
|
||||
$this->refresh();
|
||||
}
|
||||
|
||||
public function getOrDefault(string $settingName, ?string $default = null): string
|
||||
{
|
||||
if (! $this->settings instanceof Collection) {
|
||||
return (string) $default;
|
||||
}
|
||||
|
||||
return (string) $this->settings->get($settingName, $default);
|
||||
}
|
||||
|
||||
public function refresh(): void
|
||||
{
|
||||
Cache::forget('website_settings');
|
||||
|
||||
|
||||
try {
|
||||
$this->settings = Cache::remember(
|
||||
/** @var mixed $result */
|
||||
$result = Cache::remember(
|
||||
key: 'website_settings',
|
||||
ttl: now()->addMinutes(5),
|
||||
callback: fn () => Schema::hasTable('website_settings')
|
||||
? WebsiteSetting::all()->pluck('value', 'key')
|
||||
callback: fn () => Schema::hasTable('website_settings')
|
||||
? WebsiteSetting::pluck('value', 'key')
|
||||
: collect()
|
||||
);
|
||||
|
||||
/** @var array<string, string> $data */
|
||||
$data = [];
|
||||
|
||||
if ($result instanceof Collection) {
|
||||
foreach ($result as $key => $value) {
|
||||
$data[(string) $key] = is_scalar($value) ? (string) $value : '';
|
||||
}
|
||||
} elseif (is_array($result)) {
|
||||
foreach ($result as $key => $value) {
|
||||
$data[(string) $key] = is_scalar($value) ? (string) $value : '';
|
||||
}
|
||||
}
|
||||
|
||||
$this->settings = new Collection($data);
|
||||
} catch (Throwable) {
|
||||
$this->settings = collect();
|
||||
$this->settings = new Collection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user