From ae625702f1a76333e39b8ee8d023d6d0ce769e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 10 May 2024 14:20:44 -0300 Subject: [PATCH 1/9] Refactor Routing::callSetupController() to use ContainerBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Uses the ContainerBuilder to factory the setup controllers. Signed-off-by: Maurício Meneghini Fauth --- app/services_controllers.php | 13 +++++ psalm-baseline.xml | 14 ++++- .../Setup/ShowConfigController.php | 26 ++++++---- src/Routing/Routing.php | 51 +++++++++---------- tests/unit/Routing/RoutingTest.php | 31 ++++++++++- 5 files changed, 96 insertions(+), 39 deletions(-) diff --git a/app/services_controllers.php b/app/services_controllers.php index 6b21dd9851..d8983f7e2a 100644 --- a/app/services_controllers.php +++ b/app/services_controllers.php @@ -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, '@template', '@console'], + ], + Setup\ShowConfigController::class => [ + 'class' => Setup\ShowConfigController::class, + 'arguments' => ['@response'], + ], + Setup\ValidateController::class => [ + 'class' => Setup\ValidateController::class, + 'arguments' => ['@' . ResponseFactory::class], + ], Sql\ColumnPreferencesController::class => [ 'class' => Sql\ColumnPreferencesController::class, 'arguments' => ['$response' => '@response', '$dbi' => '@dbi'], diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 97b17b59f4..2888fb0074 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3029,6 +3029,19 @@ + + + + + + + + + + + + + @@ -10221,7 +10234,6 @@ - diff --git a/src/Controllers/Setup/ShowConfigController.php b/src/Controllers/Setup/ShowConfigController.php index 9a6fe7f535..0d652bb1ef 100644 --- a/src/Controllers/Setup/ShowConfigController.php +++ b/src/Controllers/Setup/ShowConfigController.php @@ -18,13 +18,16 @@ use function is_string; final class ShowConfigController implements InvocableController { + public function __construct(private readonly ResponseRenderer $responseRenderer) + { + } + public function __invoke(ServerRequest $request): Response { $formDisplay = new ConfigForm($GLOBALS['ConfigFile']); $formDisplay->save(['Config']); - $response = ResponseRenderer::getInstance(); - $response->disable(); + $this->responseRenderer->disable(); /** @var mixed $eol */ $eol = $request->getParsedBodyParam('eol'); @@ -38,10 +41,13 @@ final class ShowConfigController implements InvocableController // 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); + $this->responseRenderer->addHeader( + 'Location', + '../setup/index.php' . Url::getCommonRaw(['route' => '/setup']), + ); + $this->responseRenderer->setStatusCode(StatusCodeInterface::STATUS_SEE_OTHER); - return $response->response(); + return $this->responseRenderer->response(); } /** @var mixed $submitDownload */ @@ -49,19 +55,19 @@ final class ShowConfigController implements InvocableController if (is_string($submitDownload) && $submitDownload !== '') { // Output generated config file Core::downloadHeader('config.inc.php', 'text/plain'); - $response->disable(); + $this->responseRenderer->disable(); echo ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']); - return $response->response(); + return $this->responseRenderer->response(); } // Show generated config file in a