phpmyadmin/libraries/classes/Controllers/ThemeSetController.php
Maurício Meneghini Fauth f39e657cd9 Refactor ThemeSetController class
- Introduces ServerRequest class
- Moves UserPreferences class to constructor
- Adds unit tests

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2022-04-01 01:13:39 -03:00

54 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\ThemeManager;
use PhpMyAdmin\Url;
use PhpMyAdmin\UserPreferences;
use function is_string;
final class ThemeSetController extends AbstractController
{
/** @var ThemeManager */
private $themeManager;
/** @var UserPreferences */
private $userPreferences;
public function __construct(
ResponseRenderer $response,
Template $template,
ThemeManager $themeManager,
UserPreferences $userPreferences
) {
parent::__construct($response, $template);
$this->themeManager = $themeManager;
$this->userPreferences = $userPreferences;
}
public function __invoke(ServerRequest $request): void
{
$theme = $request->getParsedBodyParam('set_theme');
if (! $GLOBALS['cfg']['ThemeManager'] || ! is_string($theme) || $theme === '') {
$this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
return;
}
$this->themeManager->setActiveTheme($theme);
$this->themeManager->setThemeCookie();
$preferences = $this->userPreferences->load();
$preferences['config_data']['ThemeDefault'] = $theme;
$this->userPreferences->save($preferences['config_data']);
$this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
}
}