refactor(config): remove runtime config files and centralize route/bootstrap

This commit is contained in:
2026-04-01 20:27:42 +02:00
parent dba589b495
commit 5699bc6c5b
20 changed files with 487 additions and 118 deletions

View File

@@ -4,12 +4,23 @@ namespace MintyPHP\Service\Settings;
class SettingCacheService
{
private const HOT_PATH_KEYS = [
SettingKeys::APP_TITLE_KEY,
SettingKeys::APP_LOCALE_KEY,
SettingKeys::APP_THEME_KEY,
SettingKeys::APP_THEME_USER_KEY,
SettingKeys::APP_REGISTRATION_KEY,
SettingKeys::APP_PRIMARY_COLOR_KEY,
];
private ?array $settings = null;
private ?string $cacheFilePath;
private ?SettingsMetadataGateway $settingsMetadataGateway;
public function __construct(?string $cacheFilePath = null)
public function __construct(?string $cacheFilePath = null, ?SettingsMetadataGateway $settingsMetadataGateway = null)
{
$this->cacheFilePath = $cacheFilePath;
$this->settingsMetadataGateway = $settingsMetadataGateway;
}
public function get(string $key): ?string
@@ -31,7 +42,7 @@ class SettingCacheService
$file = $this->filePath();
if (!is_file($file)) {
$this->settings = [];
$this->settings = $this->hydrateColdStartCache();
return $this->settings;
}
@@ -90,7 +101,35 @@ class SettingCacheService
if (is_string($this->cacheFilePath) && $this->cacheFilePath !== '') {
return $this->cacheFilePath;
}
return dirname(__DIR__, 3) . '/config/settings.php';
$storagePath = defined('APP_STORAGE_PATH')
? (string) APP_STORAGE_PATH
: dirname(__DIR__, 3) . '/storage';
return rtrim($storagePath, '/') . '/runtime/settings.php';
}
private function hydrateColdStartCache(): array
{
if (!$this->settingsMetadataGateway instanceof SettingsMetadataGateway) {
return [];
}
$hydrated = [];
foreach (self::HOT_PATH_KEYS as $key) {
$value = $this->settingsMetadataGateway->getValue($key);
if ($value === null) {
continue;
}
$hydrated[$key] = (string) $value;
}
if ($this->write($hydrated)) {
return $this->settings ?? $hydrated;
}
$this->settings = $hydrated;
return $hydrated;
}
private function exportValue(mixed $value, int $depth = 0): string