self::COLOR_BLACK, self::THEME_WHITE => self::COLOR_BLACK, self::THEME_GRAY => self::COLOR_WHITE, self::THEME_AZURE => self::COLOR_WHITE ]; private const INIT_ERROR = 'ThemeHelper not initialized. Call initWithCurrentThemeSetting() first.'; private string $themeName; private bool $topNavTheme; private bool $sidebarTheme; private bool $darkTheme; private bool $lightTheme; private string $themeHtmlClass; private string $fgcolor; /** * Constructor for ThemeHelper * * @param string|null $theme The theme name (optional) */ public function __construct(?string $theme = null) { if ($theme === null) { throw new \RuntimeException(self::INIT_ERROR); } $this->initWithCurrentThemeSetting($theme); } /** * Initialize theme properties * * @param string $theme The theme name * @return void */ public function initWithCurrentThemeSetting(string $theme): void { $this->themeName = strtok($theme, '-'); $this->topNavTheme = in_array($this->themeName, self::TOP_NAV_THEMES); $this->sidebarTheme = in_array($this->themeName, self::SIDEBAR_THEMES); $this->darkTheme = in_array($this->themeName, self::DARK_THEMES); $this->lightTheme = in_array($this->themeName, self::LIGHT_THEMES); $this->themeHtmlClass = "Theme--{$this->themeName}"; if ($this->sidebarTheme) { $this->themeHtmlClass .= " Theme--sidebar"; } $this->fgcolor = self::FGCOLORS[$this->themeName] ?? self::COLOR_BLACK; } public function getThemeName(): string { return $this->themeName; } public function isTopNavTheme(): bool { return $this->topNavTheme; } public function isSidebarTheme(): bool { return $this->sidebarTheme; } public function isDarkTheme(): bool { return $this->darkTheme; } public function isLightTheme(): bool { return $this->lightTheme; } public function getThemeHtmlClass(): string { return $this->themeHtmlClass; } public function getFgColor(): string { return $this->fgcolor; } public function updateDockerLogColor(string $docroot): void { exec("sed -ri 's/^\.logLine\{color:#......;/.logLine{color:{$this->fgcolor};/' $docroot/plugins/dynamix.docker.manager/log.htm >/dev/null &"); } /** * Get all available theme names from the themes directory * * @param string $docroot The document root path * @return array Array of theme names */ public static function getThemesFromFileSystem(string $docroot): array { $themes = []; $themeFiles = glob("$docroot/webGui/styles/themes/*.css"); foreach ($themeFiles as $themeFile) { $themeName = basename($themeFile, '.css'); $themes[] = $themeName; } return $themes; } }