diff --git a/libraries/classes/Controllers/BrowseForeignersController.php b/libraries/classes/Controllers/BrowseForeignersController.php index f694404753..275a71572d 100644 --- a/libraries/classes/Controllers/BrowseForeignersController.php +++ b/libraries/classes/Controllers/BrowseForeignersController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers; use PhpMyAdmin\BrowseForeigners; +use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Relation; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; @@ -32,19 +33,24 @@ class BrowseForeignersController extends AbstractController $this->relation = $relation; } - public function __invoke(): void + public function __invoke(ServerRequest $request): void { - $params = [ - 'db' => $_POST['db'] ?? null, - 'table' => $_POST['table'] ?? null, - 'field' => $_POST['field'] ?? null, - 'fieldkey' => $_POST['fieldkey'] ?? null, - 'data' => $_POST['data'] ?? null, - 'foreign_showAll' => $_POST['foreign_showAll'] ?? null, - 'foreign_filter' => $_POST['foreign_filter'] ?? null, - ]; + /** @var string|null $database */ + $database = $request->getParsedBodyParam('db'); + /** @var string|null $table */ + $table = $request->getParsedBodyParam('table'); + /** @var string|null $field */ + $field = $request->getParsedBodyParam('field'); + /** @var string $fieldKey */ + $fieldKey = $request->getParsedBodyParam('fieldkey', ''); + /** @var string $data */ + $data = $request->getParsedBodyParam('data', ''); + /** @var string|null $foreignShowAll */ + $foreignShowAll = $request->getParsedBodyParam('foreign_showAll'); + /** @var string $foreignFilter */ + $foreignFilter = $request->getParsedBodyParam('foreign_filter', ''); - if (! isset($params['db'], $params['table'], $params['field'])) { + if (! isset($database, $table, $field)) { return; } @@ -54,28 +60,28 @@ class BrowseForeignersController extends AbstractController $header->setBodyId('body_browse_foreigners'); $foreigners = $this->relation->getForeigners( - $params['db'], - $params['table'] + $database, + $table ); $foreignLimit = $this->browseForeigners->getForeignLimit( - $params['foreign_showAll'] + $foreignShowAll ); $foreignData = $this->relation->getForeignData( $foreigners, - $params['field'], + $field, true, - $params['foreign_filter'] ?? '', - $foreignLimit ?? null, + $foreignFilter, + $foreignLimit ?? '', true ); $this->response->addHTML($this->browseForeigners->getHtmlForRelationalFieldSelection( - $params['db'], - $params['table'], - $params['field'], + $database, + $table, + $field, $foreignData, - $params['fieldkey'] ?? '', - $params['data'] ?? '' + $fieldKey, + $data )); } } diff --git a/libraries/classes/Controllers/CheckRelationsController.php b/libraries/classes/Controllers/CheckRelationsController.php index 776973a310..9f93ec13ca 100644 --- a/libraries/classes/Controllers/CheckRelationsController.php +++ b/libraries/classes/Controllers/CheckRelationsController.php @@ -7,6 +7,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers; +use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Relation; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; @@ -25,31 +26,32 @@ class CheckRelationsController extends AbstractController $this->relation = $relation; } - public function __invoke(): void + public function __invoke(ServerRequest $request): void { global $db; - $params = [ - 'create_pmadb' => $_POST['create_pmadb'] ?? null, - 'fixall_pmadb' => $_POST['fixall_pmadb'] ?? null, - 'fix_pmadb' => $_POST['fix_pmadb'] ?? null, - ]; + /** @var string|null $createPmaDb */ + $createPmaDb = $request->getParsedBodyParam('create_pmadb'); + /** @var string|null $fixAllPmaDb */ + $fixAllPmaDb = $request->getParsedBodyParam('fixall_pmadb'); + /** @var string|null $fixPmaDb */ + $fixPmaDb = $request->getParsedBodyParam('fix_pmadb'); $cfgStorageDbName = $this->relation->getConfigurationStorageDbName(); // If request for creating the pmadb - if (isset($params['create_pmadb']) && $this->relation->createPmaDatabase($cfgStorageDbName)) { + if (isset($createPmaDb) && $this->relation->createPmaDatabase($cfgStorageDbName)) { $this->relation->fixPmaTables($cfgStorageDbName); } // If request for creating all PMA tables. - if (isset($params['fixall_pmadb'])) { + if (isset($fixAllPmaDb)) { $this->relation->fixPmaTables($db); } $cfgRelation = $this->relation->getRelationsParam(); // If request for creating missing PMA tables. - if (isset($params['fix_pmadb'])) { + if (isset($fixPmaDb)) { $this->relation->fixPmaTables($cfgRelation['db']); } diff --git a/libraries/classes/Controllers/ColumnController.php b/libraries/classes/Controllers/ColumnController.php index 177f42740d..4beae8d011 100644 --- a/libraries/classes/Controllers/ColumnController.php +++ b/libraries/classes/Controllers/ColumnController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Message; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; @@ -24,15 +25,20 @@ final class ColumnController extends AbstractController $this->dbi = $dbi; } - public function __invoke(): void + public function __invoke(ServerRequest $request): void { - if (! isset($_POST['db'], $_POST['table'])) { + /** @var string|null $db */ + $db = $request->getParsedBodyParam('db'); + /** @var string|null $table */ + $table = $request->getParsedBodyParam('table'); + + if (! isset($db, $table)) { $this->response->setRequestStatus(false); $this->response->addJSON(['message' => Message::error()]); return; } - $this->response->addJSON(['columns' => $this->dbi->getColumnNames($_POST['db'], $_POST['table'])]); + $this->response->addJSON(['columns' => $this->dbi->getColumnNames($db, $table)]); } } diff --git a/libraries/classes/Controllers/ConfigController.php b/libraries/classes/Controllers/ConfigController.php index 714b1eed18..63c8f3d7bd 100644 --- a/libraries/classes/Controllers/ConfigController.php +++ b/libraries/classes/Controllers/ConfigController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers; use PhpMyAdmin\Config; +use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Message; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; @@ -25,28 +26,36 @@ final class ConfigController extends AbstractController $this->config = $config; } - public function get(): void + public function get(ServerRequest $request): void { - if (! isset($_POST['key'])) { + /** @var string|null $key */ + $key = $request->getParsedBodyParam('key'); + + if (! isset($key)) { $this->response->setRequestStatus(false); $this->response->addJSON(['message' => Message::error()]); return; } - $this->response->addJSON(['value' => $this->config->get($_POST['key'])]); + $this->response->addJSON(['value' => $this->config->get($key)]); } - public function set(): void + public function set(ServerRequest $request): void { - if (! isset($_POST['key'], $_POST['value'])) { + /** @var string|null $key */ + $key = $request->getParsedBodyParam('key'); + /** @var string|null $value */ + $value = $request->getParsedBodyParam('value'); + + if (! isset($key, $value)) { $this->response->setRequestStatus(false); $this->response->addJSON(['message' => Message::error()]); return; } - $result = $this->config->setUserValue(null, $_POST['key'], json_decode($_POST['value'])); + $result = $this->config->setUserValue(null, $key, json_decode($value)); if ($result === true) { return; diff --git a/libraries/classes/Controllers/ErrorReportController.php b/libraries/classes/Controllers/ErrorReportController.php index 3c2273e8e4..fbb88e5724 100644 --- a/libraries/classes/Controllers/ErrorReportController.php +++ b/libraries/classes/Controllers/ErrorReportController.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Controllers; use PhpMyAdmin\ErrorHandler; use PhpMyAdmin\ErrorReport; +use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Message; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; @@ -46,23 +47,27 @@ class ErrorReportController extends AbstractController $this->errorHandler = $errorHandler; } - public function __invoke(): void + public function __invoke(ServerRequest $request): void { global $cfg; - if ( - ! isset($_POST['exception_type']) - || ! in_array($_POST['exception_type'], ['js', 'php']) - ) { + /** @var string $exceptionType */ + $exceptionType = $request->getParsedBodyParam('exception_type', ''); + /** @var string|null $sendErrorReport */ + $sendErrorReport = $request->getParsedBodyParam('send_error_report'); + /** @var string|null $automatic */ + $automatic = $request->getParsedBodyParam('automatic'); + /** @var string|null $alwaysSend */ + $alwaysSend = $request->getParsedBodyParam('always_send'); + /** @var string|null $getSettings */ + $getSettings = $request->getParsedBodyParam('get_settings'); + + if (! in_array($exceptionType, ['js', 'php'])) { return; } - if ( - isset($_POST['send_error_report']) - && ($_POST['send_error_report'] == true - || $_POST['send_error_report'] == '1') - ) { - if ($_POST['exception_type'] === 'php') { + if ($sendErrorReport) { + if ($exceptionType === 'php') { /** * Prevent infinite error submission. * Happens in case error submissions fails. @@ -85,7 +90,7 @@ class ErrorReportController extends AbstractController } } - $reportData = $this->errorReport->getData($_POST['exception_type']); + $reportData = $this->errorReport->getData($exceptionType); // report if and only if there were 'actual' errors. if (count($reportData) > 0) { $server_response = $this->errorReport->send($reportData); @@ -99,11 +104,7 @@ class ErrorReportController extends AbstractController /* Message to show to the user */ if ($success) { - if ( - (isset($_POST['automatic']) - && $_POST['automatic'] === 'true') - || $cfg['SendErrorReports'] === 'always' - ) { + if ($automatic === 'true' || $cfg['SendErrorReports'] === 'always') { $msg = __( 'An error has been detected and an error report has been ' . 'automatically submitted based on your settings.' @@ -134,35 +135,32 @@ class ErrorReportController extends AbstractController /* Add message to response */ if ($this->response->isAjax()) { - if ($_POST['exception_type'] === 'js') { + if ($exceptionType === 'js') { $this->response->addJSON('message', $msg); } else { $this->response->addJSON('errSubmitMsg', $msg); } - } elseif ($_POST['exception_type'] === 'php') { + } elseif ($exceptionType === 'php') { $jsCode = 'Functions.ajaxShowMessage(\'
$params['message']
- $params['data'] ?? ''
- $params['db']
- $params['db']
- $params['field']
- $params['field']
- $params['fieldkey'] ?? ''
- $params['foreign_filter'] ?? ''
- $params['foreign_showAll']
- $params['table']
- $params['table']
- $foreignLimit ?? null
- readgzfile
@@ -1110,18 +1093,9 @@
$db
$_POST['db']
- $_POST['table']
- $_POST['key']
- $_POST['key']
- $_POST['value']
- json_decode($_POST['value'])
+ json_decode($value)
$_POST['exception_type']
- $decoded_response['success']
$_GET['db']
$_GET['table']
- $controllerName
$action
- $controllerName
- $controller
- [$controllerName, $action]
- $action
-