phpmyadmin/libraries/classes/Controllers/Setup/ShowConfigController.php
Maurício Meneghini Fauth c0d04b6895
Add a Response object to ResponseRenderer class
Uses a Response object to handle the HTTP headers and HTTP status code.

This makes the AbstractNetworkTestCase obsolete and removes it.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2023-08-07 22:27:48 -03:00

64 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config\Forms\Setup\ConfigForm;
use PhpMyAdmin\Core;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Setup\ConfigGenerator;
use PhpMyAdmin\Url;
use function is_string;
final class ShowConfigController
{
public function __invoke(ServerRequest $request): void
{
$formDisplay = new ConfigForm($GLOBALS['ConfigFile']);
$formDisplay->save(['Config']);
$response = ResponseRenderer::getInstance();
$response->disable();
/** @var mixed $eol */
$eol = $request->getParsedBodyParam('eol');
if ($eol !== null) {
$_SESSION['eol'] = $eol === 'unix' ? 'unix' : 'win';
}
/** @var mixed $submitClear */
$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);
$response->callExit();
}
/** @var mixed $submitDownload */
$submitDownload = $request->getParsedBodyParam('submit_download');
if (is_string($submitDownload) && $submitDownload !== '') {
// Output generated config file
Core::downloadHeader('config.inc.php', 'text/plain');
$response->disable();
echo ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']);
return;
}
// Show generated config file in a <textarea>
$response->addHeader(
'Location',
'../setup/index.php' . Url::getCommonRaw(['route' => '/setup', 'page' => 'config']),
);
$response->setStatusCode(StatusCodeInterface::STATUS_SEE_OTHER);
$response->callExit();
}
}