Merge pull request #19156 from MauricioFauth/setup-controllers

Refactor setup controllers to implement InvocableController
This commit is contained in:
Maurício Meneghini Fauth 2024-05-13 11:09:36 -03:00 committed by GitHub
commit 510e442593
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 732 additions and 628 deletions

View File

@ -29,6 +29,7 @@ use PhpMyAdmin\Controllers\PhpInfoController;
use PhpMyAdmin\Controllers\Preferences;
use PhpMyAdmin\Controllers\SchemaExportController;
use PhpMyAdmin\Controllers\Server;
use PhpMyAdmin\Controllers\Setup;
use PhpMyAdmin\Controllers\Sql;
use PhpMyAdmin\Controllers\Table;
use PhpMyAdmin\Controllers\TableController;
@ -866,6 +867,18 @@ return [
'class' => Server\VariablesController::class,
'arguments' => ['$response' => '@response', '$template' => '@template', '$dbi' => '@dbi'],
],
Setup\MainController::class => [
'class' => Setup\MainController::class,
'arguments' => ['@' . ResponseFactory::class, '@response', '@template', '@config'],
],
Setup\ShowConfigController::class => [
'class' => Setup\ShowConfigController::class,
'arguments' => ['@' . ResponseFactory::class, '@template', '@config'],
],
Setup\ValidateController::class => [
'class' => Setup\ValidateController::class,
'arguments' => ['@' . ResponseFactory::class, '@template', '@config'],
],
Sql\ColumnPreferencesController::class => [
'class' => Sql\ColumnPreferencesController::class,
'arguments' => ['$response' => '@response', '$dbi' => '@dbi'],

View File

@ -3025,81 +3025,26 @@ parameters:
count: 1
path: src/Controllers/Operations/ViewController.php
-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/ExportController.php
-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ExportController.php
-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ExportController.php
-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/FeaturesController.php
-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/FeaturesController.php
-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/FeaturesController.php
-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/ImportController.php
-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ImportController.php
-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ImportController.php
-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/MainPanelController.php
-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/MainPanelController.php
-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/MainPanelController.php
-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 2
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Cannot call method getFlatDefaultConfig\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Cannot call method resetConfigData\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Only booleans are allowed in an if condition, PhpMyAdmin\\\\Message\\|string given\\.$#"
count: 1
@ -3115,16 +3060,6 @@ parameters:
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#1 \\$cf of class PhpMyAdmin\\\\Config\\\\Forms\\\\User\\\\UserFormList constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#1 \\$fileName of method PhpMyAdmin\\\\UserPreferences\\:\\:redirect\\(\\) expects string, string\\|false given\\.$#"
count: 1
@ -3160,46 +3095,16 @@ parameters:
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
count: 2
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, \\(int\\|string\\) given\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/NavigationController.php
-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/NavigationController.php
-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/NavigationController.php
-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/SqlController.php
-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/SqlController.php
-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
@ -3750,11 +3655,26 @@ parameters:
count: 1
path: src/Controllers/Server/Variables/SetVariableController.php
-
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/ConfigController.php
-
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/FormController.php
-
message: "#^Only booleans are allowed in a ternary operator condition, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/HomeController.php
-
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/HomeController.php
-
message: "#^Parameter \\#1 \\$id of method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:getServerName\\(\\) expects int, \\(int\\|string\\) given\\.$#"
count: 1
@ -3766,47 +3686,22 @@ parameters:
path: src/Controllers/Setup/HomeController.php
-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\ConfigController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php
-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\FormController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php
-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\HomeController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php
-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\ServersController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php
path: src/Controllers/Setup/ServerDestroyController.php
-
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php
path: src/Controllers/Setup/ServersController.php
-
message: "#^Cannot call method resetConfigData\\(\\) on mixed\\.$#"
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/ShowConfigController.php
-
message: "#^Parameter \\#1 \\$cf of class PhpMyAdmin\\\\Config\\\\Forms\\\\Setup\\\\ConfigForm constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/ShowConfigController.php
-
message: "#^Parameter \\#1 \\$cf of static method PhpMyAdmin\\\\Setup\\\\ConfigGenerator\\:\\:getConfigFile\\(\\) expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/ShowConfigController.php
-
message: "#^Parameter \\#1 \\$cf of static method PhpMyAdmin\\\\Config\\\\Validator\\:\\:validate\\(\\) expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/ValidateController.php
@ -15230,11 +15125,6 @@ parameters:
count: 2
path: tests/unit/Config/ServerConfigChecksTest.php
-
message: "#^Parameter \\#1 \\$cfg of class PhpMyAdmin\\\\Config\\\\ServerConfigChecks constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 3
path: tests/unit/Config/ServerConfigChecksTest.php
-
message: "#^Property PhpMyAdmin\\\\Tests\\\\Config\\\\ServerConfigChecksTest\\:\\:\\$sessionID \\(string\\) does not accept mixed\\.$#"
count: 1

View File

@ -2306,7 +2306,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
@ -2314,7 +2313,6 @@
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
@ -2328,7 +2326,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
@ -2336,7 +2333,6 @@
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
@ -2350,7 +2346,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
@ -2358,7 +2353,6 @@
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
@ -2372,7 +2366,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
@ -2380,7 +2373,6 @@
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
@ -2394,7 +2386,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['query']]]></code>
</InvalidArrayOffset>
<MixedArgument>
@ -2407,7 +2398,6 @@
<code><![CDATA[$key]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['query']]]></code>
<code><![CDATA[$_POST[str_replace('/', '-', (string) $k)]]]></code>
<code><![CDATA[$configuration]]></code>
@ -2453,7 +2443,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
@ -2461,7 +2450,6 @@
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
@ -2475,7 +2463,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
@ -2483,7 +2470,6 @@
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
@ -3014,21 +3000,28 @@
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/Setup/HomeController.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<MixedArgumentTypeCoercion>
<code><![CDATA[$id]]></code>
<code><![CDATA[$id]]></code>
</MixedArgumentTypeCoercion>
<RiskyTruthyFalsyComparison>
<code><![CDATA[Config::getInstance()->get('PMA_IS_WINDOWS')]]></code>
<code><![CDATA[$this->config->get('PMA_IS_WINDOWS')]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Controllers/Setup/MainController.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Setup/ShowConfigController.php">
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Setup/ValidateController.php">
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Sql/ColumnPreferencesController.php">
<MixedAssignment>
@ -10225,7 +10218,6 @@
<file src="src/Routing/Routing.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<MixedArrayAccess>
<code><![CDATA[$dispatchData[0]['GET']['/']]]></code>
@ -14688,11 +14680,6 @@
<code><![CDATA[$result]]></code>
</MixedAssignment>
</file>
<file src="tests/unit/Setup/FormProcessingTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
</file>
<file src="tests/unit/Setup/IndexTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>

View File

@ -49,7 +49,6 @@
complete_query: string,
compression: 'none'|'zip'|'gzip',
conn_error: string,
ConfigFile: PhpMyAdmin\Config\ConfigFile,
csv_columns: bool,
csv_enclosed: string,
csv_escaped: string,

View File

@ -65,15 +65,15 @@ class PageSettings
$this->groupName = $formGroupName;
$cf = new ConfigFile(Config::getInstance()->baseSettings);
$this->userPreferences->pageInit($cf);
$configFile = new ConfigFile(Config::getInstance()->baseSettings);
$this->userPreferences->pageInit($configFile);
$formDisplay = new $formClass($cf);
$formDisplay = new $formClass($configFile);
// Process form
$error = null;
if (isset($_POST['submit_save']) && $_POST['submit_save'] == $formGroupName) {
$error = $this->processPageSettings($formDisplay, $cf);
$error = $this->processPageSettings($formDisplay, $configFile);
}
// Display forms

View File

@ -35,15 +35,14 @@ final class ExportController implements InvocableController
public function __invoke(ServerRequest $request): Response|null
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['tabHash'] ??= null;
$GLOBALS['hash'] ??= null;
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
$formDisplay = new ExportForm($GLOBALS['cf'], 1);
$formDisplay = new ExportForm($configFile, 1);
if ($request->hasBodyParam('revert')) {
// revert erroneous fields to their default values
@ -58,7 +57,7 @@ final class ExportController implements InvocableController
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
$result = $this->userPreferences->save($configFile->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {

View File

@ -35,15 +35,14 @@ final class FeaturesController implements InvocableController
public function __invoke(ServerRequest $request): Response|null
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['tabHash'] ??= null;
$GLOBALS['hash'] ??= null;
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
$formDisplay = new FeaturesForm($GLOBALS['cf'], 1);
$formDisplay = new FeaturesForm($configFile, 1);
if ($request->hasBodyParam('revert')) {
// revert erroneous fields to their default values
@ -58,7 +57,7 @@ final class FeaturesController implements InvocableController
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
$result = $this->userPreferences->save($configFile->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {

View File

@ -35,15 +35,14 @@ final class ImportController implements InvocableController
public function __invoke(ServerRequest $request): Response|null
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['tabHash'] ??= null;
$GLOBALS['hash'] ??= null;
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
$formDisplay = new ImportForm($GLOBALS['cf'], 1);
$formDisplay = new ImportForm($configFile, 1);
if ($request->hasBodyParam('revert')) {
// revert erroneous fields to their default values
@ -58,7 +57,7 @@ final class ImportController implements InvocableController
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
$result = $this->userPreferences->save($configFile->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {

View File

@ -35,15 +35,14 @@ final class MainPanelController implements InvocableController
public function __invoke(ServerRequest $request): Response|null
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['tabHash'] ??= null;
$GLOBALS['hash'] ??= null;
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
$formDisplay = new MainForm($GLOBALS['cf'], 1);
$formDisplay = new MainForm($configFile, 1);
if ($request->hasBodyParam('revert')) {
// revert erroneous fields to their default values
@ -58,7 +57,7 @@ final class MainPanelController implements InvocableController
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
$result = $this->userPreferences->save($configFile->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {

View File

@ -58,15 +58,14 @@ final class ManageController implements InvocableController
public function __invoke(ServerRequest $request): Response|null
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['lang'] ??= null;
$GLOBALS['query'] ??= null;
$route = $request->getRoute();
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
$GLOBALS['error'] = '';
if ($request->hasBodyParam('submit_export') && $request->getParsedBodyParam('export_type') === 'text_file') {
@ -142,10 +141,10 @@ final class ManageController implements InvocableController
} else {
// sanitize input values: treat them as though
// they came from HTTP POST request
$formDisplay = new UserFormList($GLOBALS['cf']);
$newConfig = $GLOBALS['cf']->getFlatDefaultConfig();
$formDisplay = new UserFormList($configFile);
$newConfig = $configFile->getFlatDefaultConfig();
if ($request->hasBodyParam('import_merge')) {
$newConfig = array_merge($newConfig, $GLOBALS['cf']->getConfigArray());
$newConfig = array_merge($newConfig, $configFile->getConfigArray());
}
$newConfig = array_merge($newConfig, $configuration);
@ -154,7 +153,7 @@ final class ManageController implements InvocableController
$_POST[str_replace('/', '-', (string) $k)] = $v;
}
$GLOBALS['cf']->resetConfigData();
$configFile->resetConfigData();
$allOk = $formDisplay->process(true, false);
$allOk = $allOk && ! $formDisplay->hasErrors();
$_POST = $postParamBackup;
@ -200,7 +199,7 @@ final class ManageController implements InvocableController
}
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
$result = $this->userPreferences->save($configFile->getConfigArray());
if ($result === true) {
if ($returnUrl) {
$GLOBALS['query'] = Util::splitURLQuery($returnUrl);

View File

@ -35,15 +35,14 @@ final class NavigationController implements InvocableController
public function __invoke(ServerRequest $request): Response|null
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['tabHash'] ??= null;
$GLOBALS['hash'] ??= null;
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
$formDisplay = new NaviForm($GLOBALS['cf'], 1);
$formDisplay = new NaviForm($configFile, 1);
if ($request->hasBodyParam('revert')) {
// revert erroneous fields to their default values
@ -58,7 +57,7 @@ final class NavigationController implements InvocableController
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
$result = $this->userPreferences->save($configFile->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {

View File

@ -35,15 +35,14 @@ final class SqlController implements InvocableController
public function __invoke(ServerRequest $request): Response|null
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['tabHash'] ??= null;
$GLOBALS['hash'] ??= null;
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
$formDisplay = new SqlForm($GLOBALS['cf'], 1);
$formDisplay = new SqlForm($configFile, 1);
if ($request->hasBodyParam('revert')) {
// revert erroneous fields to their default values
@ -58,7 +57,7 @@ final class SqlController implements InvocableController
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
$result = $this->userPreferences->save($configFile->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {

View File

@ -4,37 +4,79 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Setup\ConfigGenerator;
use PhpMyAdmin\Setup\SetupHelper;
use PhpMyAdmin\Template;
use function __;
use function file_exists;
use function is_string;
class ConfigController extends AbstractController
{
/**
* @param mixed[] $params Request parameters
*
* @return string HTML
*/
public function __invoke(array $params): string
{
$formset = isset($params['formset']) && is_string($params['formset']) ? $params['formset'] : '';
$eol = isset($params['eol']) && $params['eol'] === 'win' ? 'win' : 'unix';
use const CONFIG_FILE;
$pages = $this->getPages();
final class ConfigController implements InvocableController
{
public function __construct(
private readonly ResponseFactory $responseFactory,
private readonly ResponseRenderer $responseRenderer,
private readonly Template $template,
private readonly Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
if (@file_exists(CONFIG_FILE) && ! $this->config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Configuration already exists, setup is disabled!'),
]));
}
$response = $this->responseFactory->createResponse();
foreach ($this->responseRenderer->getHeader()->getHttpHeaders() as $name => $value) {
$response = $response->withHeader($name, $value);
}
$pages = SetupHelper::getPages();
static $hasCheckPageRefresh = false;
if (! $hasCheckPageRefresh) {
$hasCheckPageRefresh = true;
}
$config = ConfigGenerator::getConfigFile($this->config);
$configFile = SetupHelper::createConfigFile();
return $this->template->render('setup/config/index', [
'formset' => $formset,
$config = ConfigGenerator::getConfigFile($configFile);
return $response->write($this->template->render('setup/config/index', [
'formset' => $this->getFormSetParam($request->getQueryParam('formset')),
'pages' => $pages,
'eol' => $eol,
'eol' => $this->getEolParam($request->getQueryParam('eol')),
'config' => $config,
'has_check_page_refresh' => $hasCheckPageRefresh,
]);
]));
}
private function getFormSetParam(mixed $formSetParam): string
{
return is_string($formSetParam) ? $formSetParam : '';
}
/** @psalm-return 'win'|'unix' */
private function getEolParam(mixed $eolParam): string
{
return $eolParam === 'win' ? 'win' : 'unix';
}
}

View File

@ -4,47 +4,134 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\Forms\Setup\SetupFormList;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\Setup\FormProcessing;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Setup\SetupHelper;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use function __;
use function file_exists;
use function in_array;
use function is_numeric;
use function is_string;
use function ob_get_clean;
use function ob_start;
class FormController extends AbstractController
use const CONFIG_FILE;
final class FormController implements InvocableController
{
/**
* @param mixed[] $params Request parameters
*
* @return string HTML
*/
public function __invoke(array $params): string
public function __construct(
private readonly ResponseFactory $responseFactory,
private readonly ResponseRenderer $responseRenderer,
private readonly Template $template,
private readonly Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
$pages = $this->getPages();
if (@file_exists(CONFIG_FILE) && ! $this->config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
$formset = isset($params['formset']) && is_string($params['formset']) ? $params['formset'] : '';
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Configuration already exists, setup is disabled!'),
]));
}
$formClass = SetupFormList::get($formset);
$response = $this->responseFactory->createResponse();
foreach ($this->responseRenderer->getHeader()->getHttpHeaders() as $name => $value) {
$response = $response->withHeader($name, $value);
}
$pages = SetupHelper::getPages();
$formSet = $this->getFormSetParam($request->getQueryParam('formset'));
$formClass = SetupFormList::get($formSet);
if ($formClass === null) {
return $this->template->render('error/generic', [
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Incorrect form specified!'),
]);
]));
}
ob_start();
$form = new $formClass($this->config);
FormProcessing::process($form);
$page = ob_get_clean();
$configFile = SetupHelper::createConfigFile();
$formDisplay = new $formClass($configFile);
return $this->template->render('setup/form/index', [
'formset' => $formset,
'pages' => $pages,
'name' => $form::getName(),
'page' => $page,
if ($request->getQueryParam('mode') === 'revert') {
// revert erroneous fields to their default values
$formDisplay->fixErrors();
return $response->withStatus(StatusCodeInterface::STATUS_FOUND)
->withHeader('Location', '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
}
if (! $formDisplay->process(false)) {
// handle form view and failed POST
return $response->write($this->template->render('setup/form/index', [
'formset' => $formSet,
'pages' => $pages,
'name' => $formDisplay::getName(),
'page' => $formDisplay->getDisplay(),
]));
}
// check for form errors
if (! $formDisplay->hasErrors()) {
return $response->withStatus(StatusCodeInterface::STATUS_FOUND)
->withHeader('Location', '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
}
$page = $this->getPageParam($request->getQueryParam('page'));
$id = $this->getIdParam($request->getQueryParam('id'));
if ($id === 0 && $page === 'servers') {
// we've just added a new server, get its id
$id = $formDisplay->getConfigFile()->getServerCount();
}
$errors = $this->template->render('setup/error', [
'url_params' => ['page' => $page, 'formset' => $formSet, 'id' => $id],
'errors' => $formDisplay->displayErrors(),
]);
return $response->write($this->template->render('setup/form/index', [
'formset' => $formSet,
'pages' => $pages,
'name' => $formDisplay::getName(),
'page' => $errors,
]));
}
private function getFormSetParam(mixed $formSetParam): string
{
return is_string($formSetParam) ? $formSetParam : '';
}
/** @psalm-return 'form'|'config'|'servers'|'index' */
private function getPageParam(mixed $pageParam): string
{
return in_array($pageParam, ['form', 'config', 'servers'], true) ? $pageParam : 'index';
}
/** @psalm-return int<0, max> */
private function getIdParam(mixed $idParam): int
{
if (! is_numeric($idParam)) {
return 0;
}
$id = (int) $idParam;
return $id >= 1 ? $id : 0;
}
}

View File

@ -4,39 +4,68 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\ServerConfigChecks;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Setup\Index;
use PhpMyAdmin\Setup\SetupHelper;
use PhpMyAdmin\Template;
use function __;
use function array_keys;
use function file_exists;
use function is_scalar;
use function is_string;
class HomeController extends AbstractController
{
/**
* @param mixed[] $params Request parameters
*
* @return string HTML
*/
public function __invoke(array $params): string
{
$formset = isset($params['formset']) && is_string($params['formset']) ? $params['formset'] : '';
use const CONFIG_FILE;
$pages = $this->getPages();
final class HomeController implements InvocableController
{
public function __construct(
private readonly ResponseFactory $responseFactory,
private readonly ResponseRenderer $responseRenderer,
private readonly Template $template,
private readonly Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
if (@file_exists(CONFIG_FILE) && ! $this->config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Configuration already exists, setup is disabled!'),
]));
}
$response = $this->responseFactory->createResponse();
foreach ($this->responseRenderer->getHeader()->getHttpHeaders() as $name => $value) {
$response = $response->withHeader($name, $value);
}
$pages = SetupHelper::getPages();
// message handling
Index::messagesBegin();
// Check phpMyAdmin version
if (isset($params['version_check'])) {
if ($request->hasQueryParam('version_check')) {
Index::versionCheck();
}
$configFile = SetupHelper::createConfigFile();
// Perform various security, compatibility and consistency checks
$configChecker = new ServerConfigChecks($this->config);
$configChecker = new ServerConfigChecks($configFile);
$configChecker->performConfigChecks();
$text = __(
@ -66,12 +95,12 @@ class HomeController extends AbstractController
}
$servers = [];
foreach (array_keys($this->config->getServers()) as $id) {
foreach (array_keys($configFile->getServers()) as $id) {
$servers[$id] = [
'id' => $id,
'name' => $this->config->getServerName($id),
'auth_type' => $this->config->getValue('Servers/' . $id . '/auth_type'),
'dsn' => $this->config->getServerDSN($id),
'name' => $configFile->getServerName($id),
'auth_type' => $configFile->getValue('Servers/' . $id . '/auth_type'),
'dsn' => $configFile->getServerDSN($id),
'params' => [
'token' => $_SESSION[' PMA_token '],
'edit' => ['page' => 'servers', 'mode' => 'edit', 'id' => $id],
@ -85,17 +114,22 @@ class HomeController extends AbstractController
$hasCheckPageRefresh = true;
}
return $this->template->render('setup/home/index', [
'formset' => $formset,
return $response->write($this->template->render('setup/home/index', [
'formset' => $this->getFormSetParam($request->getQueryParam('formset')),
'languages' => $languages,
'messages' => $messages,
'server_count' => $this->config->getServerCount(),
'server_count' => $configFile->getServerCount(),
'servers' => $servers,
'pages' => $pages,
'has_check_page_refresh' => $hasCheckPageRefresh,
'eol' => isset($_SESSION['eol']) && is_scalar($_SESSION['eol'])
? $_SESSION['eol']
: (Config::getInstance()->get('PMA_IS_WINDOWS') ? 'win' : 'unix'),
]);
: ($this->config->get('PMA_IS_WINDOWS') ? 'win' : 'unix'),
]));
}
private function getFormSetParam(mixed $formSetParam): string
{
return is_string($formSetParam) ? $formSetParam : '';
}
}

View File

@ -4,94 +4,76 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Console;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Header;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use function __;
use function file_exists;
use function in_array;
use const CONFIG_FILE;
final class MainController implements InvocableController
{
public function __construct(
private readonly ResponseFactory $responseFactory,
private readonly ResponseRenderer $responseRenderer,
private readonly Template $template,
private readonly Console $console,
private readonly Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
$config = Config::getInstance();
if (@file_exists(CONFIG_FILE) && ! $config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Configuration already exists, setup is disabled!'),
]));
}
/** @var mixed $pageParam */
$pageParam = $request->getQueryParam('page');
$page = in_array($pageParam, ['form', 'config', 'servers'], true) ? $pageParam : 'index';
$response = $this->responseFactory->createResponse();
$header = new Header($this->template, $this->console, $config);
foreach ($header->getHttpHeaders() as $name => $value) {
// Sent security-related headers
$response = $response->withHeader($name, $value);
}
$page = $this->getPageParam($request->getQueryParam('page'));
if ($page === 'form') {
return $response->write((new FormController($GLOBALS['ConfigFile'], $this->template))([
'formset' => $request->getQueryParam('formset'),
]));
return (new FormController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
if ($page === 'config') {
return $response->write((new ConfigController($GLOBALS['ConfigFile'], $this->template))([
'formset' => $request->getQueryParam('formset'),
'eol' => $request->getQueryParam('eol'),
]));
return (new ConfigController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
if ($page === 'servers' && $request->getQueryParam('mode') === 'remove' && $request->isPost()) {
return (new ServerDestroyController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
if ($page === 'servers') {
$controller = new ServersController($GLOBALS['ConfigFile'], $this->template);
/** @var mixed $mode */
$mode = $request->getQueryParam('mode');
if ($mode === 'remove' && $request->isPost()) {
$controller->destroy(['id' => $request->getQueryParam('id')]);
$response = $response->withStatus(StatusCodeInterface::STATUS_FOUND);
return $response->withHeader(
'Location',
'../setup/index.php' . Url::getCommonRaw(['route' => '/setup']),
);
}
return $response->write($controller->index([
'formset' => $request->getQueryParam('formset'),
'mode' => $mode,
'id' => $request->getQueryParam('id'),
]));
return (new ServersController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
return $response->write((new HomeController($GLOBALS['ConfigFile'], $this->template))([
'formset' => $request->getQueryParam('formset'),
'version_check' => $request->getQueryParam('version_check'),
]));
return (new HomeController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
/** @psalm-return 'form'|'config'|'servers'|'index' */
private function getPageParam(mixed $pageParam): string
{
return in_array($pageParam, ['form', 'config', 'servers'], true) ? $pageParam : 'index';
}
}

View File

@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Setup\SetupHelper;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use function __;
use function file_exists;
use function is_numeric;
use const CONFIG_FILE;
final class ServerDestroyController implements InvocableController
{
public function __construct(
private readonly ResponseFactory $responseFactory,
private readonly ResponseRenderer $responseRenderer,
private readonly Template $template,
private readonly Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
if (@file_exists(CONFIG_FILE) && ! $this->config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Configuration already exists, setup is disabled!'),
]));
}
$response = $this->responseFactory->createResponse();
foreach ($this->responseRenderer->getHeader()->getHttpHeaders() as $name => $value) {
$response = $response->withHeader($name, $value);
}
$configFile = SetupHelper::createConfigFile();
$id = $this->getIdParam($request->getQueryParam('id'));
$hasServer = $id >= 1 && $configFile->get('Servers/' . $id) !== null;
if ($hasServer) {
$configFile->removeServer($id);
}
return $response->withStatus(StatusCodeInterface::STATUS_FOUND)->withHeader(
'Location',
'../setup/index.php' . Url::getCommonRaw(['route' => '/setup']),
);
}
/** @psalm-return int<0, max> */
private function getIdParam(mixed $idParam): int
{
if (! is_numeric($idParam)) {
return 0;
}
$id = (int) $idParam;
return $id >= 1 ? $id : 0;
}
}

View File

@ -4,65 +4,146 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\Forms\Setup\ServersForm;
use PhpMyAdmin\Setup\FormProcessing;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Setup\SetupHelper;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use function __;
use function file_exists;
use function in_array;
use function is_numeric;
use function is_string;
use function ob_get_clean;
use function ob_start;
class ServersController extends AbstractController
use const CONFIG_FILE;
final class ServersController implements InvocableController
{
/**
* @param mixed[] $params Request parameters
*
* @return string HTML
*/
public function index(array $params): string
public function __construct(
private readonly ResponseFactory $responseFactory,
private readonly ResponseRenderer $responseRenderer,
private readonly Template $template,
private readonly Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
$formset = isset($params['formset']) && is_string($params['formset']) ? $params['formset'] : '';
$id = isset($params['id']) && is_numeric($params['id']) && (int) $params['id'] >= 1 ? (int) $params['id'] : 0;
$mode = '';
if (isset($params['mode']) && in_array($params['mode'], ['add', 'edit', 'revert'], true)) {
$mode = $params['mode'];
if (@file_exists(CONFIG_FILE) && ! $this->config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Configuration already exists, setup is disabled!'),
]));
}
$pages = $this->getPages();
$response = $this->responseFactory->createResponse();
foreach ($this->responseRenderer->getHeader()->getHttpHeaders() as $name => $value) {
$response = $response->withHeader($name, $value);
}
$hasServer = $id >= 1 && $this->config->get('Servers/' . $id) !== null;
$configFile = SetupHelper::createConfigFile();
$id = $this->getIdParam($request->getQueryParam('id'));
$mode = $this->getModeParam($request->getQueryParam('mode'));
$pages = SetupHelper::getPages();
$hasServer = $id >= 1 && $configFile->get('Servers/' . $id) !== null;
if (! $hasServer && $mode !== 'revert' && $mode !== 'edit') {
$id = 0;
}
ob_start();
FormProcessing::process(new ServersForm($this->config, $id));
$page = ob_get_clean();
$formDisplay = new ServersForm($configFile, $id);
return $this->template->render('setup/servers/index', [
'formset' => $formset,
if ($mode === 'revert') {
// revert erroneous fields to their default values
$formDisplay->fixErrors();
return $response->withStatus(StatusCodeInterface::STATUS_FOUND)
->withHeader('Location', '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
}
$formSet = $this->getFormSetParam($request->getQueryParam('formset'));
if (! $formDisplay->process(false)) {
// handle form view and failed POST
return $response->write($this->template->render('setup/servers/index', [
'formset' => $formSet,
'pages' => $pages,
'has_server' => $hasServer,
'mode' => $mode,
'server_id' => $id,
'server_dsn' => $configFile->getServerDSN($id),
'page' => $formDisplay->getDisplay(),
]));
}
// check for form errors
if (! $formDisplay->hasErrors()) {
return $response->withStatus(StatusCodeInterface::STATUS_FOUND)
->withHeader('Location', '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
}
$page = $this->getPageParam($request->getQueryParam('page'));
if ($id === 0 && $page === 'servers') {
// we've just added a new server, get its id
$id = $formDisplay->getConfigFile()->getServerCount();
}
$errors = $this->template->render('setup/error', [
'url_params' => ['page' => $page, 'formset' => $formSet, 'id' => $id],
'errors' => $formDisplay->displayErrors(),
]);
return $response->write($this->template->render('setup/servers/index', [
'formset' => $formSet,
'pages' => $pages,
'has_server' => $hasServer,
'mode' => $mode,
'server_id' => $id,
'server_dsn' => $this->config->getServerDSN($id),
'page' => $page,
]);
'server_dsn' => $configFile->getServerDSN($id),
'page' => $errors,
]));
}
/** @param mixed[] $params Request parameters */
public function destroy(array $params): void
private function getFormSetParam(mixed $formSetParam): string
{
$id = isset($params['id']) && is_numeric($params['id']) && (int) $params['id'] >= 1 ? (int) $params['id'] : 0;
return is_string($formSetParam) ? $formSetParam : '';
}
$hasServer = $id >= 1 && $this->config->get('Servers/' . $id) !== null;
/** @psalm-return 'add'|'edit'|'revert'|'' */
private function getModeParam(mixed $modeParam): string
{
return in_array($modeParam, ['add', 'edit', 'revert'], true) ? $modeParam : '';
}
if (! $hasServer) {
return;
/** @psalm-return int<0, max> */
private function getIdParam(mixed $idParam): int
{
if (! is_numeric($idParam)) {
return 0;
}
$this->config->removeServer($id);
$id = (int) $idParam;
return $id >= 1 ? $id : 0;
}
/** @psalm-return 'form'|'config'|'servers'|'index' */
private function getPageParam(mixed $pageParam): string
{
return in_array($pageParam, ['form', 'config', 'servers'], true) ? $pageParam : 'index';
}
}

View File

@ -5,26 +5,50 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\Forms\Setup\ConfigForm;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Core;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\Setup\ConfigGenerator;
use PhpMyAdmin\Setup\SetupHelper;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use function __;
use function file_exists;
use function is_string;
use const CONFIG_FILE;
final class ShowConfigController implements InvocableController
{
public function __construct(
private readonly ResponseFactory $responseFactory,
private readonly Template $template,
private readonly Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
$formDisplay = new ConfigForm($GLOBALS['ConfigFile']);
$formDisplay->save(['Config']);
if (@file_exists(CONFIG_FILE) && ! $this->config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
$response = ResponseRenderer::getInstance();
$response->disable();
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Configuration already exists, setup is disabled!'),
]));
}
$configFile = SetupHelper::createConfigFile();
$formDisplay = new ConfigForm($configFile);
$formDisplay->save(['Config']);
/** @var mixed $eol */
$eol = $request->getParsedBodyParam('eol');
@ -36,32 +60,26 @@ final class ShowConfigController implements InvocableController
$submitClear = $request->getParsedBodyParam('submit_clear');
if (is_string($submitClear) && $submitClear !== '') {
// Clear current config and return to main page
$GLOBALS['ConfigFile']->resetConfigData();
// drop post data
$response->addHeader('Location', '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
$response->setStatusCode(StatusCodeInterface::STATUS_SEE_OTHER);
$configFile->resetConfigData();
return $response->response();
return $this->responseFactory->createResponse(StatusCodeInterface::STATUS_FOUND)
->withHeader('Location', '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
}
/** @var mixed $submitDownload */
$submitDownload = $request->getParsedBodyParam('submit_download');
if (is_string($submitDownload) && $submitDownload !== '') {
$response = $this->responseFactory->createResponse();
// Output generated config file
Core::downloadHeader('config.inc.php', 'text/plain');
$response->disable();
echo ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']);
return $response->response();
return $response->write(ConfigGenerator::getConfigFile($configFile));
}
// Show generated config file in a <textarea>
$response->addHeader(
return $this->responseFactory->createResponse(StatusCodeInterface::STATUS_FOUND)->withHeader(
'Location',
'../setup/index.php' . Url::getCommonRaw(['route' => '/setup', 'page' => 'config']),
);
$response->setStatusCode(StatusCodeInterface::STATUS_SEE_OTHER);
return $response->response();
}
}

View File

@ -4,30 +4,51 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\Validator;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Core;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\Setup\SetupHelper;
use PhpMyAdmin\Template;
use stdClass;
use function __;
use function explode;
use function file_exists;
use function implode;
use function is_string;
use function json_decode;
use function json_encode;
use function sprintf;
use const CONFIG_FILE;
final class ValidateController implements InvocableController
{
public function __construct(private readonly ResponseFactory $responseFactory)
{
public function __construct(
private readonly ResponseFactory $responseFactory,
private readonly Template $template,
private readonly Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
if (@file_exists(CONFIG_FILE) && ! $this->config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
return $response->write($this->template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => __('Configuration already exists, setup is disabled!'),
]));
}
$response = $this->responseFactory->createResponse();
foreach (Core::headerJSON() as $name => $value) {
$response = $response->withHeader($name, $value);
@ -44,8 +65,10 @@ final class ValidateController implements InvocableController
return $response->write((string) json_encode(['success' => false, 'message' => __('Wrong data')]));
}
$configFile = SetupHelper::createConfigFile();
$values = (array) $values;
$result = Validator::validate($GLOBALS['ConfigFile'], $vids, $values, true);
$result = Validator::validate($configFile, $vids, $values, true);
if ($result === false) {
$result = sprintf(
__('Wrong data or no validation for %s'),

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Http\Middleware;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\ConfigFile;
use PhpMyAdmin\Container\ContainerBuilder;
use PhpMyAdmin\Exceptions\ExitException;
use PhpMyAdmin\Http\Factory\ResponseFactory;
@ -57,21 +56,6 @@ final class SetupPageRedirection implements MiddlewareInterface
$this->config->setCookie('pma_lang', $GLOBALS['lang']);
$this->config->set('is_setup', true);
$GLOBALS['ConfigFile'] = new ConfigFile();
$GLOBALS['ConfigFile']->setPersistKeys([
'DefaultLang',
'ServerDefault',
'UploadDir',
'SaveDir',
'Servers/1/verbose',
'Servers/1/host',
'Servers/1/port',
'Servers/1/socket',
'Servers/1/auth_type',
'Servers/1/user',
'Servers/1/password',
]);
// allows for redirection even after sending some data
ob_start();
}

View File

@ -10,17 +10,14 @@ use FastRoute\Dispatcher\GroupCountBased as DispatcherGroupCountBased;
use FastRoute\RouteCollector;
use FastRoute\RouteParser\Std as RouteParserStd;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Bookmarks\BookmarkRepository;
use PhpMyAdmin\Config;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Console;
use PhpMyAdmin\Container\ContainerBuilder;
use PhpMyAdmin\Controllers\HomeController;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Controllers\Setup\MainController;
use PhpMyAdmin\Controllers\Setup\ShowConfigController;
use PhpMyAdmin\Controllers\Setup\ValidateController;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
@ -190,33 +187,33 @@ class Routing
public static function callSetupController(ServerRequest $request, ResponseFactory $responseFactory): Response
{
$route = $request->getRoute();
$template = new Template();
if ($route === '/setup' || $route === '/') {
$dbi = DatabaseInterface::getInstance();
$relation = new Relation($dbi);
$console = new Console($relation, $template, new BookmarkRepository($dbi, $relation));
$controllerName = match ($route) {
'/', '/setup' => MainController::class,
'/setup/show-config' => ShowConfigController::class,
'/setup/validate' => ValidateController::class,
default => null,
};
return (new MainController($responseFactory, $template, $console))($request);
$container = ContainerBuilder::getContainer();
if ($controllerName === null) {
$template = $container->get('template');
assert($template instanceof Template);
$response = $responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
return $response->write($template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => Sanitize::convertBBCode(sprintf(
__('Error 404! The page %s was not found.'),
'[code]' . htmlspecialchars($route) . '[/code]',
)),
]));
}
if ($route === '/setup/show-config') {
return (new ShowConfigController())($request);
}
$controller = $container->get($controllerName);
assert($controller instanceof $controllerName);
if ($route === '/setup/validate') {
return (new ValidateController($responseFactory))($request);
}
$response = $responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
return $response->write($template->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => LanguageManager::$textDir,
'error_message' => Sanitize::convertBBCode(sprintf(
__('Error 404! The page %s was not found.'),
'[code]' . htmlspecialchars($route) . '[/code]',
)),
]));
return $controller($request);
}
/**

View File

@ -1,76 +0,0 @@
<?php
/**
* Formset processing library
*/
declare(strict_types=1);
namespace PhpMyAdmin\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config\FormDisplay;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use function in_array;
use function is_numeric;
use function is_string;
/**
* PhpMyAdmin\Setup\FormProcessing class
*/
class FormProcessing
{
/**
* Processes forms registered in $form_display, handles error correction
*
* @param FormDisplay $formDisplay Form to display
*/
public static function process(FormDisplay $formDisplay): void
{
if (isset($_GET['mode']) && $_GET['mode'] === 'revert') {
// revert erroneous fields to their default values
$formDisplay->fixErrors();
$response = ResponseRenderer::getInstance();
$response->disable();
$response->addHeader('Location', '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
$response->setStatusCode(StatusCodeInterface::STATUS_SEE_OTHER);
$response->callExit();
}
if (! $formDisplay->process(false)) {
// handle form view and failed POST
echo $formDisplay->getDisplay();
return;
}
// check for form errors
if (! $formDisplay->hasErrors()) {
$response = ResponseRenderer::getInstance();
$response->disable();
$response->addHeader('Location', '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
$response->setStatusCode(StatusCodeInterface::STATUS_SEE_OTHER);
$response->callExit();
}
// form has errors, show warning
$page = 'index';
if (isset($_GET['page']) && in_array($_GET['page'], ['form', 'config', 'servers'], true)) {
$page = $_GET['page'];
}
$formset = isset($_GET['formset']) && is_string($_GET['formset']) ? $_GET['formset'] : '';
$formId = isset($_GET['id']) && is_numeric($_GET['id']) && (int) $_GET['id'] >= 1 ? (int) $_GET['id'] : 0;
if ($formId === 0 && $page === 'servers') {
// we've just added a new server, get its id
$formId = $formDisplay->getConfigFile()->getServerCount();
}
$urlParams = ['page' => $page, 'formset' => $formset, 'id' => $formId];
$template = new Template();
echo $template->render('setup/error', ['url_params' => $urlParams, 'errors' => $formDisplay->displayErrors()]);
}
}

View File

@ -2,23 +2,38 @@
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
namespace PhpMyAdmin\Setup;
use PhpMyAdmin\Config\ConfigFile;
use PhpMyAdmin\Config\Forms\BaseForm;
use PhpMyAdmin\Config\Forms\Setup\SetupFormList;
use PhpMyAdmin\Template;
use function in_array;
abstract class AbstractController
final class SetupHelper
{
public function __construct(protected ConfigFile $config, protected Template $template)
public static function createConfigFile(): ConfigFile
{
$configFile = new ConfigFile();
$configFile->setPersistKeys([
'DefaultLang',
'ServerDefault',
'UploadDir',
'SaveDir',
'Servers/1/verbose',
'Servers/1/host',
'Servers/1/port',
'Servers/1/socket',
'Servers/1/auth_type',
'Servers/1/user',
'Servers/1/password',
]);
return $configFile;
}
/** @return string[][] */
protected function getPages(): array
public static function getPages(): array
{
$ignored = ['Config', 'Servers'];
$pages = [];

View File

@ -24,6 +24,8 @@ class ServerConfigChecksTest extends AbstractTestCase
{
private string $sessionID;
private ConfigFile $configFile;
/** @throws ReflectionException */
protected function setUp(): void
{
@ -35,11 +37,10 @@ class ServerConfigChecksTest extends AbstractTestCase
$config->settings['AvailableCharsets'] = [];
$config->settings['ServerDefault'] = 0;
$cf = new ConfigFile();
$GLOBALS['ConfigFile'] = $cf;
$this->configFile = new ConfigFile();
$reflection = new ReflectionProperty(ConfigFile::class, 'id');
$this->sessionID = $reflection->getValue($cf);
$this->sessionID = $reflection->getValue($this->configFile);
unset($_SESSION['messages']);
unset($_SESSION[$this->sessionID]);
@ -70,7 +71,7 @@ class ServerConfigChecksTest extends AbstractTestCase
$configChecker = $this->getMockBuilder(ServerConfigChecks::class)
->onlyMethods(['functionExists'])
->setConstructorArgs([$GLOBALS['ConfigFile']])
->setConstructorArgs([$this->configFile])
->getMock();
// Configure the stub.
@ -113,7 +114,7 @@ class ServerConfigChecksTest extends AbstractTestCase
$_SESSION[$this->sessionID]['BZipDump'] = false;
$_SESSION[$this->sessionID]['ZipDump'] = false;
$configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
$configChecker = new ServerConfigChecks($this->configFile);
$configChecker->performConfigChecks();
/**
@ -141,7 +142,7 @@ class ServerConfigChecksTest extends AbstractTestCase
'1' => ['host' => 'localhost', 'ssl' => true, 'auth_type' => 'cookie', 'AllowRoot' => false],
];
$configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
$configChecker = new ServerConfigChecks($this->configFile);
$configChecker->performConfigChecks();
/**
@ -167,7 +168,7 @@ class ServerConfigChecksTest extends AbstractTestCase
$_SESSION[$this->sessionID]['blowfish_secret'] = str_repeat('a', SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
$_SESSION[$this->sessionID]['Servers'] = ['1' => ['host' => 'localhost', 'auth_type' => 'cookie']];
$configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
$configChecker = new ServerConfigChecks($this->configFile);
$configChecker->performConfigChecks();
/**

View File

@ -5,12 +5,18 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Routing;
use FastRoute\Dispatcher;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Container\ContainerBuilder;
use PhpMyAdmin\Controllers\HomeController;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Routing\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Container\ContainerInterface;
use function copy;
use function unlink;
@ -19,7 +25,7 @@ use const CACHE_DIR;
use const TEST_PATH;
#[CoversClass(Routing::class)]
class RoutingTest extends AbstractTestCase
final class RoutingTest extends AbstractTestCase
{
/**
* Test for Routing::getDispatcher
@ -97,4 +103,27 @@ class RoutingTest extends AbstractTestCase
['', '/phpmyadmin/index.php', '', '/phpmyadmin/index.php'],
];
}
public function testCallSetupControllerWithInvalidRoute(): void
{
$template = new Template();
$container = self::createStub(ContainerInterface::class);
$container->method('get')->willReturn($template);
ContainerBuilder::$container = $container;
$request = ServerRequestFactory::create()->createServerRequest('GET', 'https://example.com/')
->withAttribute('route', '/setup/invalid-route');
$response = Routing::callSetupController($request, ResponseFactory::create());
$expected = $template->render('error/generic', [
'lang' => 'en',
'dir' => 'ltr',
'error_message' => 'Error 404! The page <code>/setup/invalid-route</code> was not found.',
]);
self::assertSame(StatusCodeInterface::STATUS_NOT_FOUND, $response->getStatusCode());
self::assertSame($expected, (string) $response->getBody());
ContainerBuilder::$container = null;
}
}

View File

@ -1,119 +0,0 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Setup;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\FormDisplay;
use PhpMyAdmin\Current;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Exceptions\ExitException;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Setup\FormProcessing;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseRendererStub;
use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionProperty;
use Throwable;
use function ob_get_clean;
use function ob_start;
#[CoversClass(FormProcessing::class)]
class FormProcessingTest extends AbstractTestCase
{
/**
* Prepares environment for the test.
*/
protected function setUp(): void
{
parent::setUp();
$this->setLanguage();
Current::$database = 'db';
Current::$table = 'table';
Config::getInstance()->settings['ServerDefault'] = 1;
}
public function testProcessFormSet(): void
{
DatabaseInterface::$instance = $this->createDatabaseInterface();
$responseStub = new ResponseRendererStub();
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseStub);
// case 1
$formDisplay = $this->getMockBuilder(FormDisplay::class)
->disableOriginalConstructor()
->onlyMethods(['process', 'getDisplay'])
->getMock();
$formDisplay->expects(self::once())
->method('process')
->with(false)
->willReturn(false);
$formDisplay->expects(self::once())
->method('getDisplay');
FormProcessing::process($formDisplay);
// case 2
$formDisplay = $this->getMockBuilder(FormDisplay::class)
->disableOriginalConstructor()
->onlyMethods(['process', 'hasErrors', 'displayErrors'])
->getMock();
$formDisplay->expects(self::once())
->method('process')
->with(false)
->willReturn(true);
$formDisplay->expects(self::once())
->method('hasErrors')
->with()
->willReturn(true);
ob_start();
FormProcessing::process($formDisplay);
$result = ob_get_clean();
self::assertIsString($result);
self::assertStringContainsString('<div class="error">', $result);
self::assertStringContainsString('mode=revert', $result);
self::assertStringContainsString('<a class="btn" href="../setup/index.php?route=/setup&', $result);
self::assertStringContainsString('mode=edit', $result);
// case 3
$formDisplay = $this->getMockBuilder(FormDisplay::class)
->disableOriginalConstructor()
->onlyMethods(['process', 'hasErrors'])
->getMock();
$formDisplay->expects(self::once())
->method('process')
->with(false)
->willReturn(true);
$formDisplay->expects(self::once())
->method('hasErrors')
->with()
->willReturn(false);
try {
FormProcessing::process($formDisplay);
} catch (Throwable $throwable) {
}
self::assertInstanceOf(ExitException::class, $throwable ?? null);
$response = $responseStub->getResponse();
self::assertSame(['../setup/index.php?route=%2Fsetup&lang=en'], $response->getHeader('Location'));
self::assertSame(303, $response->getStatusCode());
}
}

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Setup;
use PhpMyAdmin\Setup\SetupHelper;
use PhpMyAdmin\Tests\AbstractTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(SetupHelper::class)]
final class SetupHelperTest extends AbstractTestCase
{
public function testCreateConfigFile(): void
{
$expected = [
'DefaultLang' => 0,
'ServerDefault' => 1,
'UploadDir' => 2,
'SaveDir' => 3,
'Servers/1/verbose' => 4,
'Servers/1/host' => 5,
'Servers/1/port' => 6,
'Servers/1/socket' => 7,
'Servers/1/auth_type' => 8,
'Servers/1/user' => 9,
'Servers/1/password' => 10,
];
$configFile = SetupHelper::createConfigFile();
self::assertSame($expected, $configFile->getPersistKeysMap());
self::assertNotSame($configFile, SetupHelper::createConfigFile());
}
public function testGetPages(): void
{
$expected = [
'Export' => ['name' => 'Export', 'formset' => 'Export'],
'Features' => ['name' => 'Features', 'formset' => 'Features'],
'Import' => ['name' => 'Import', 'formset' => 'Import'],
'Main' => ['name' => 'Main panel', 'formset' => 'Main'],
'Navi' => ['name' => 'Navigation panel', 'formset' => 'Navi'],
'Sql' => ['name' => 'SQL queries', 'formset' => 'Sql'],
];
self::assertSame($expected, SetupHelper::getPages());
}
}