generated from boboko/starter
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Spatie\YamlFrontMatter\YamlFrontMatter;
|
|
|
|
/**
|
|
* Site-wide, marketing-editable settings from Stoic's `settings` singleton
|
|
* (resources/stoic/content/settings.md). Read directly rather than through a
|
|
* Paper model: Paper models map to a folder of entries, and this is one file
|
|
* at the content root. Legal and transactional details (address, ΑΦΜ, phone)
|
|
* live in boboko-core's StoreDetails instead.
|
|
*
|
|
* Bound as scoped in AppServiceProvider, so the file is parsed once per
|
|
* request (or queued job) and edits in Stoic show up on the next one.
|
|
*/
|
|
class StoicSettings
|
|
{
|
|
private const SOCIALS = [
|
|
'facebook' => 'Facebook',
|
|
'instagram' => 'Instagram',
|
|
'tiktok' => 'TikTok',
|
|
];
|
|
|
|
private array $data;
|
|
|
|
public function __construct()
|
|
{
|
|
$path = resource_path('stoic/content/settings.md');
|
|
|
|
$this->data = is_file($path)
|
|
? YamlFrontMatter::parse(file_get_contents($path))->matter()
|
|
: [];
|
|
}
|
|
|
|
public function get(string $key, mixed $default = null): mixed
|
|
{
|
|
return filled($this->data[$key] ?? null) ? $this->data[$key] : $default;
|
|
}
|
|
|
|
/**
|
|
* Only the networks that have a URL set, in display order.
|
|
*
|
|
* @return list<array{icon: string, label: string, url: string}>
|
|
*/
|
|
public function socialLinks(): array
|
|
{
|
|
$links = [];
|
|
|
|
foreach (self::SOCIALS as $icon => $label) {
|
|
if ($url = $this->get("{$icon}_url")) {
|
|
$links[] = ['icon' => $icon, 'label' => $label, 'url' => $url];
|
|
}
|
|
}
|
|
|
|
return $links;
|
|
}
|
|
}
|