Files
breadcrumb-the-shire/lib/Service/Settings/ThemeConfigService.php

47 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace MintyPHP\Service\Settings;
class ThemeConfigService
{
private const DEFAULT_THEMES = [
'light' => 'Light',
'dark' => 'Dark',
];
2026-02-23 12:58:19 +01:00
private ?array $themes = null;
2026-02-23 12:58:19 +01:00
public function all(): array
{
2026-02-23 12:58:19 +01:00
if ($this->themes !== null) {
return $this->themes;
}
$file = dirname(__DIR__, 3) . '/config/themes.php';
if (!is_file($file)) {
2026-02-23 12:58:19 +01:00
$this->themes = self::DEFAULT_THEMES;
return $this->themes;
}
$loaded = include $file;
if (!is_array($loaded)) {
2026-02-23 12:58:19 +01:00
$this->themes = self::DEFAULT_THEMES;
return $this->themes;
}
$clean = [];
foreach ($loaded as $key => $label) {
$themeKey = strtolower(trim((string) $key));
$themeLabel = trim((string) $label);
if ($themeKey === '' || $themeLabel === '') {
continue;
}
$clean[$themeKey] = $themeLabel;
}
2026-03-06 00:44:52 +01:00
// Fall back to defaults if the file returns an empty or invalid list — system must always have themes.
2026-02-23 12:58:19 +01:00
$this->themes = $clean ?: self::DEFAULT_THEMES;
return $this->themes;
}
}