46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace MintyPHP\Service\Settings;
|
||
|
|
|
||
|
|
class ThemeConfigService
|
||
|
|
{
|
||
|
|
private const DEFAULT_THEMES = [
|
||
|
|
'light' => 'Light',
|
||
|
|
'dark' => 'Dark',
|
||
|
|
];
|
||
|
|
|
||
|
|
private static ?array $themes = null;
|
||
|
|
|
||
|
|
public static function all(): array
|
||
|
|
{
|
||
|
|
if (self::$themes !== null) {
|
||
|
|
return self::$themes;
|
||
|
|
}
|
||
|
|
|
||
|
|
$file = dirname(__DIR__, 3) . '/config/themes.php';
|
||
|
|
if (!is_file($file)) {
|
||
|
|
self::$themes = self::DEFAULT_THEMES;
|
||
|
|
return self::$themes;
|
||
|
|
}
|
||
|
|
|
||
|
|
$loaded = include $file;
|
||
|
|
if (!is_array($loaded)) {
|
||
|
|
self::$themes = self::DEFAULT_THEMES;
|
||
|
|
return self::$themes;
|
||
|
|
}
|
||
|
|
|
||
|
|
$clean = [];
|
||
|
|
foreach ($loaded as $key => $label) {
|
||
|
|
$themeKey = strtolower(trim((string) $key));
|
||
|
|
$themeLabel = trim((string) $label);
|
||
|
|
if ($themeKey === '' || $themeLabel === '') {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
$clean[$themeKey] = $themeLabel;
|
||
|
|
}
|
||
|
|
|
||
|
|
self::$themes = $clean ?: self::DEFAULT_THEMES;
|
||
|
|
return self::$themes;
|
||
|
|
}
|
||
|
|
}
|