forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request phpmyadmin#19494 from kamil-tekiela/Refactor-Theme…
…Manager Refactor ThemeManager
- Loading branch information
Showing
6 changed files
with
36 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
use function __; | ||
use function array_key_exists; | ||
use function htmlspecialchars; | ||
use function is_string; | ||
use function ksort; | ||
use function sprintf; | ||
|
||
|
@@ -30,7 +29,7 @@ class ThemeManager | |
private string $themesPathUrl; | ||
|
||
/** @var array<string,Theme> available themes */ | ||
public array $themes = []; | ||
private array $themes = []; | ||
|
||
/** @var string cookie name */ | ||
public string $cookieName = 'pma_theme'; | ||
|
@@ -62,8 +61,7 @@ public function initializeTheme(): void | |
|
||
$this->loadThemes(); | ||
|
||
$configThemeExists = $this->checkTheme($config->settings['ThemeDefault']); | ||
if (! $configThemeExists) { | ||
if (! $this->themeExists($config->settings['ThemeDefault'])) { | ||
throw new MissingTheme(sprintf( | ||
__('Default theme %s not found!'), | ||
htmlspecialchars($config->settings['ThemeDefault']), | ||
|
@@ -74,19 +72,18 @@ public function initializeTheme(): void | |
|
||
// check if user have a theme cookie | ||
$cookieTheme = $this->getThemeCookie(); | ||
if ( | ||
$cookieTheme && $this->setActiveTheme($cookieTheme) | ||
|| $configThemeExists && $this->setActiveTheme($this->themeDefault) | ||
) { | ||
$colorMode = $this->getColorModeCookie(); | ||
if (is_string($colorMode) && $colorMode !== '') { | ||
$this->theme->setColorMode($colorMode); | ||
} | ||
if ($cookieTheme !== '') { | ||
$this->setActiveTheme($cookieTheme); | ||
} else { | ||
$this->setActiveTheme($this->themeDefault); | ||
Check warning on line 78 in src/Theme/ThemeManager.php GitHub Actions / Infection (8.2, ubuntu-latest)
|
||
} | ||
|
||
$colorMode = $this->getColorModeCookie(); | ||
if ($colorMode === '') { | ||
Check warning on line 82 in src/Theme/ThemeManager.php GitHub Actions / Infection (8.2, ubuntu-latest)
|
||
return; | ||
} | ||
|
||
$this->setActiveTheme(self::FALLBACK_THEME); | ||
$this->theme->setColorMode($colorMode); | ||
} | ||
|
||
/** | ||
|
@@ -102,21 +99,19 @@ public function setThemePerServer(bool $perServer): void | |
/** | ||
* Sets active theme | ||
* | ||
* @param string|null $theme theme name | ||
* @param string $theme theme name | ||
*/ | ||
public function setActiveTheme(string|null $theme): bool | ||
public function setActiveTheme(string $theme): void | ||
Check warning on line 104 in src/Theme/ThemeManager.php GitHub Actions / Infection (8.2, ubuntu-latest)
|
||
{ | ||
if (! $this->checkTheme($theme)) { | ||
if (! $this->themeExists($theme)) { | ||
throw new MissingTheme(sprintf( | ||
__('Theme %s not found!'), | ||
htmlspecialchars((string) $theme), | ||
htmlspecialchars($theme), | ||
)); | ||
} | ||
|
||
$this->activeTheme = $theme; | ||
$this->theme = $this->themes[$theme]; | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
|
@@ -141,34 +136,30 @@ private function getColorModeCookieName(): string | |
|
||
/** | ||
* returns name of theme stored in the cookie | ||
* | ||
* @return string|false theme name from cookie or false | ||
*/ | ||
public function getThemeCookie(): string|false | ||
public function getThemeCookie(): string | ||
{ | ||
$name = $this->getThemeCookieName(); | ||
$config = Config::getInstance(); | ||
if ($config->issetCookie($name)) { | ||
return $config->getCookie($name); | ||
return (string) $config->getCookie($name); | ||
Check warning on line 145 in src/Theme/ThemeManager.php GitHub Actions / Infection (8.2, ubuntu-latest)
|
||
} | ||
|
||
return false; | ||
return ''; | ||
} | ||
|
||
/** | ||
* returns name of theme stored in the cookie | ||
* | ||
* @return string|false theme name from cookie or false | ||
*/ | ||
public function getColorModeCookie(): string|false | ||
private function getColorModeCookie(): string | ||
{ | ||
$name = $this->getColorModeCookieName(); | ||
$config = Config::getInstance(); | ||
if ($config->issetCookie($name)) { | ||
Check warning on line 158 in src/Theme/ThemeManager.php GitHub Actions / Infection (8.2, ubuntu-latest)
|
||
return $config->getCookie($name); | ||
return (string) $config->getCookie($name); | ||
} | ||
|
||
return false; | ||
return ''; | ||
} | ||
|
||
public function setThemeCookie(): void | ||
|
@@ -220,11 +211,11 @@ public function loadThemes(): void | |
/** | ||
* checks if given theme name is a known theme | ||
* | ||
* @param string|null $theme name fo theme to check for | ||
* @param string $theme name fo theme to check for | ||
*/ | ||
public function checkTheme(string|null $theme): bool | ||
public function themeExists(string $theme): bool | ||
Check warning on line 216 in src/Theme/ThemeManager.php GitHub Actions / Infection (8.2, ubuntu-latest)
|
||
{ | ||
return array_key_exists($theme ?? '', $this->themes); | ||
return array_key_exists($theme, $this->themes); | ||
} | ||
|
||
/** @return array{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters