3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Controllers
;
8 use PhpMyAdmin\Http\ServerRequest
;
9 use PhpMyAdmin\ResponseRenderer
;
10 use PhpMyAdmin\Template
;
11 use PhpMyAdmin\Theme\ThemeManager
;
13 use PhpMyAdmin\UserPreferences
;
15 use function is_string
;
17 final class ThemeSetController
extends AbstractController
19 public function __construct(
20 ResponseRenderer
$response,
22 private ThemeManager
$themeManager,
23 private UserPreferences
$userPreferences,
25 parent
::__construct($response, $template);
28 public function __invoke(ServerRequest
$request): void
30 $theme = $request->getParsedBodyParam('set_theme');
31 if (! Config
::getInstance()->settings
['ThemeManager'] ||
! is_string($theme) ||
$theme === '') {
32 if ($request->isAjax()) {
33 $this->response
->addJSON('themeColorMode', '');
38 $this->response
->redirect('index.php?route=/' . Url
::getCommonRaw([], '&'));
43 $this->themeManager
->setActiveTheme($theme);
45 /** @var mixed $themeColorMode */
46 $themeColorMode = $request->getParsedBodyParam('themeColorMode');
47 if (is_string($themeColorMode) && $themeColorMode !== '') {
48 $this->themeManager
->theme
->setColorMode($themeColorMode);
51 $this->themeManager
->setThemeCookie();
53 $preferences = $this->userPreferences
->load();
54 $preferences['config_data']['ThemeDefault'] = $theme;
55 $this->userPreferences
->save($preferences['config_data']);
57 if ($request->isAjax()) {
58 $this->response
->addJSON('themeColorMode', $this->themeManager
->theme
->getColorMode());
63 $this->response
->redirect('index.php?route=/' . Url
::getCommonRaw([], '&'));