refactor(theme): drop dark-green and collapse theme registry to light/dark

Remove the extensible theme catalog (config/themes.php + ThemeConfigGateway)
in favor of a two-entry const on SettingsAppGateway. appThemes() now returns
the list directly — no container lookup, no file include. Drop the
dark-green theme assets, narrow [data-theme^="dark"] selectors to
[data-theme="dark"], and tighten isDarkTheme() to an exact match. Ship an
idempotent migration that corrects any leftover 'dark-green' rows on users
and tenants to safe defaults (light / NULL).

Tenant scoping (default_theme, allow_user_theme) and per-user override stay
intact; only the catalog extensibility and the third theme are removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 16:15:10 +02:00
parent 4b9ce4bbad
commit 0002c07755
19 changed files with 29 additions and 153 deletions

View File

@@ -26,7 +26,6 @@ use MintyPHP\Service\Settings\SettingsSessionGateway;
use MintyPHP\Service\Settings\SettingsSmtpGateway;
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
use MintyPHP\Service\Settings\SettingsUserLifecycleGateway;
use MintyPHP\Service\Settings\ThemeConfigGateway;
use MintyPHP\Service\Tenant\TenantService;
final class SettingsRegistrar implements ContainerRegistrar
@@ -65,7 +64,6 @@ final class SettingsRegistrar implements ContainerRegistrar
$c->get(ApiTokenRepository::class),
$c->get(AuditRecorderInterface::class)
));
$container->set(ThemeConfigGateway::class, static fn (AppContainer $c): ThemeConfigGateway => $c->get(SettingServicesFactory::class)->createThemeConfigGateway());
// Branding services are registered here because they depend on settings gateways
// and are consumed alongside settings (e.g. in UserAccessPdfService and the admin UI).
$container->set(BrandingLogoService::class, static fn (AppContainer $c): BrandingLogoService => $c->get(BrandingServicesFactory::class)->createBrandingLogoService());

View File

@@ -9,7 +9,6 @@ use MintyPHP\Repository\Tenant\TenantRepositoryInterface;
class SettingServicesFactory
{
private ?ThemeConfigGateway $themeConfigService = null;
private ?SettingCacheService $settingCacheService = null;
private ?SettingsCryptoGatewayInterface $settingsCryptoGateway = null;
private ?SettingsMetadataGateway $settingsMetadataGateway = null;
@@ -53,7 +52,6 @@ class SettingServicesFactory
{
return $this->settingsAppGateway ??= new SettingsAppGateway(
$this->createSettingsMetadataGateway(),
$this->createThemeConfigGateway(),
);
}
@@ -108,11 +106,6 @@ class SettingServicesFactory
);
}
public function createThemeConfigGateway(): ThemeConfigGateway
{
return $this->themeConfigService ??= new ThemeConfigGateway();
}
public function createSettingsCryptoGateway(): SettingsCryptoGatewayInterface
{
return $this->settingsCryptoGateway ??= new SettingsCryptoGateway();

View File

@@ -13,15 +13,18 @@ use MintyPHP\I18n;
*
* The theme CATALOG utilities (listThemes, isAllowedTheme, normalizeTheme,
* resolveDefaultTheme) stay because consumers across Tenant / Auth / User
* flows need to validate a theme value and resolve a safe default. There is
* no global setting lookup in these helpers anymore — the default is a
* hardcoded 'light' falling back to the first available catalog entry.
* flows need to validate a theme value and resolve a safe default. The
* catalog is a fixed two-entry list; 'light' is the hardcoded default.
*/
class SettingsAppGateway
{
private const THEMES = [
'light' => 'Light',
'dark' => 'Dark',
];
public function __construct(
private readonly SettingsMetadataGateway $settingsMetadataGateway,
private readonly ThemeConfigGateway $themeConfigService
) {
}
@@ -82,14 +85,11 @@ class SettingsAppGateway
}
/**
* Catalog of available themes — purely code-level (config/themes.php),
* not a global setting.
*
* @return array<string, string>
*/
public function listThemes(): array
{
return $this->themeConfigService->all();
return self::THEMES;
}
public function isAllowedTheme(?string $theme): bool

View File

@@ -1,46 +0,0 @@
<?php
namespace MintyPHP\Service\Settings;
class ThemeConfigGateway
{
private const DEFAULT_THEMES = [
'light' => 'Light',
'dark' => 'Dark',
];
private ?array $themes = null;
public function all(): array
{
if ($this->themes !== null) {
return $this->themes;
}
$file = dirname(__DIR__, 3) . '/config/themes.php';
if (!is_file($file)) {
$this->themes = self::DEFAULT_THEMES;
return $this->themes;
}
$loaded = include $file;
if (!is_array($loaded)) {
$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;
}
// Fall back to defaults if the file returns an empty or invalid list — system must always have themes.
$this->themes = $clean ?: self::DEFAULT_THEMES;
return $this->themes;
}
}

View File

@@ -7,18 +7,16 @@
*/
/**
* Load configured themes with a safe fallback list.
* Available themes. Fixed two-entry catalog — light and dark.
*
* @return array<string, string>
*/
function appThemes(): array
{
if (!class_exists('MintyPHP\\Service\\Settings\\ThemeConfigGateway')) {
return [
'light' => 'Light',
'dark' => 'Dark',
];
}
return app(\MintyPHP\Service\Settings\ThemeConfigGateway::class)->all();
return [
'light' => 'Light',
'dark' => 'Dark',
];
}
/**