Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ResponseRenderer::disable() from controllers #19149

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions app/services_controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
],
ChangeLogController::class => [
'class' => ChangeLogController::class,
'arguments' => ['$response' => '@response', '$config' => '@config'],
'arguments' => ['@response', '@config', '@' . ResponseFactory::class, '@template'],
],
CheckRelationsController::class => [
'class' => CheckRelationsController::class,
Expand Down Expand Up @@ -219,7 +219,7 @@
],
Database\Structure\AddPrefixController::class => [
'class' => Database\Structure\AddPrefixController::class,
'arguments' => ['$response' => '@response'],
'arguments' => ['@response', '@' . ResponseFactory::class, '@template'],
],
Database\Structure\AddPrefixTableController::class => [
'class' => Database\Structure\AddPrefixTableController::class,
Expand Down Expand Up @@ -251,11 +251,11 @@
],
Database\Structure\ChangePrefixFormController::class => [
'class' => Database\Structure\ChangePrefixFormController::class,
'arguments' => ['$response' => '@response'],
'arguments' => ['@response', '@' . ResponseFactory::class, '@template'],
],
Database\Structure\CopyFormController::class => [
'class' => Database\Structure\CopyFormController::class,
'arguments' => ['$response' => '@response'],
'arguments' => ['@response', '@' . ResponseFactory::class, '@template'],
],
Database\Structure\CopyTableController::class => [
'class' => Database\Structure\CopyTableController::class,
Expand Down Expand Up @@ -448,12 +448,9 @@
],
LicenseController::class => [
'class' => LicenseController::class,
'arguments' => ['$response' => '@response'],
],
LintController::class => [
'class' => LintController::class,
'arguments' => ['$response' => '@response'],
'arguments' => ['@response', '@' . ResponseFactory::class],
],
LintController::class => ['class' => LintController::class, 'arguments' => ['@' . ResponseFactory::class]],
LogoutController::class => [
'class' => LogoutController::class,
'arguments' => ['@' . AuthenticationPluginFactory::class],
Expand Down Expand Up @@ -541,7 +538,7 @@
],
PhpInfoController::class => [
'class' => PhpInfoController::class,
'arguments' => ['$response' => '@response'],
'arguments' => ['@response', '@' . ResponseFactory::class, '@config'],
],
Preferences\ExportController::class => [
'class' => Preferences\ExportController::class,
Expand Down Expand Up @@ -591,6 +588,7 @@
'$relation' => '@relation',
'$config' => '@config',
'$themeManager' => '@' . PhpMyAdmin\Theme\ThemeManager::class,
'$responseFactory' => '@' . ResponseFactory::class,
],
],
Preferences\NavigationController::class => [
Expand Down Expand Up @@ -619,7 +617,7 @@
],
SchemaExportController::class => [
'class' => SchemaExportController::class,
'arguments' => ['$export' => '@export', '$response' => '@response'],
'arguments' => ['@export', '@response', '@' . ResponseFactory::class],
],
Server\BinlogController::class => [
'class' => Server\BinlogController::class,
Expand Down Expand Up @@ -988,7 +986,7 @@
],
Table\GetFieldController::class => [
'class' => Table\GetFieldController::class,
'arguments' => ['$response' => '@response', '$dbi' => '@dbi'],
'arguments' => ['@response', '@dbi', '@' . ResponseFactory::class],
],
Table\GisVisualizationController::class => [
'class' => Table\GisVisualizationController::class,
Expand All @@ -997,6 +995,7 @@
'$template' => '@template',
'$dbi' => '@dbi',
'$dbTableExists' => '@' . DbTableExists::class,
'$responseFactory' => '@' . ResponseFactory::class,
],
],
Table\ImportController::class => [
Expand Down Expand Up @@ -1263,6 +1262,7 @@
'$tracking' => '@tracking',
'$trackingChecker' => '@tracking_checker',
'$dbTableExists' => '@' . DbTableExists::class,
'$responseFactory' => '@' . ResponseFactory::class,
],
],
Triggers\IndexController::class => [
Expand Down Expand Up @@ -1318,6 +1318,7 @@
'$relation' => '@relation',
'$dbi' => '@dbi',
'$dbTableExists' => '@' . DbTableExists::class,
'$responseFactory' => '@' . ResponseFactory::class,
],
],
UserPasswordController::class => [
Expand All @@ -1326,7 +1327,7 @@
],
VersionCheckController::class => [
'class' => VersionCheckController::class,
'arguments' => ['$response' => '@response', '$versionInformation' => '@version_information'],
'arguments' => ['@version_information', '@' . ResponseFactory::class],
],
View\CreateController::class => [
'class' => View\CreateController::class,
Expand Down
12 changes: 1 addition & 11 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,7 @@ parameters:
path: src/Controllers/LicenseController.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function printf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
message: "#^Parameter \\#1 \\$path of function basename expects string, mixed given\\.$#"
count: 1
path: src/Controllers/LicenseController.php

Expand Down Expand Up @@ -4380,16 +4380,6 @@ parameters:
count: 3
path: src/Controllers/Table/GetFieldController.php

-
message: "#^Parameter \\#1 \\$string of function mb_strlen expects string, string\\|null given\\.$#"
count: 1
path: src/Controllers/Table/GetFieldController.php

-
message: "#^Parameter \\#1 \\$test of static method PhpMyAdmin\\\\Mime\\:\\:detect\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/Controllers/Table/GetFieldController.php

-
message: "#^Cannot access offset 'back' on mixed\\.$#"
count: 1
Expand Down
63 changes: 5 additions & 58 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,6 @@
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/ChangeLogController.php">
<PossiblyUnusedReturnValue>
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/CheckRelationsController.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
Expand Down Expand Up @@ -1305,11 +1300,6 @@
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Database/Structure/AddPrefixController.php">
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Database/Structure/AddPrefixTableController.php">
<MixedOperand>
<code><![CDATA[$request->getParsedBodyParam('add_prefix', '')]]></code>
Expand Down Expand Up @@ -1339,18 +1329,10 @@
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Database/Structure/ChangePrefixFormController.php">
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Database/Structure/CopyFormController.php">
<DeprecatedMethod>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Database/Structure/CopyTableController.php">
<MixedArgument>
Expand Down Expand Up @@ -2045,19 +2027,11 @@
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/LicenseController.php">
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/LintController.php">
<MixedAssignment>
<code><![CDATA[$editorType]]></code>
<code><![CDATA[$options]]></code>
</MixedAssignment>
<PossiblyUnusedReturnValue>
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/LogoutController.php">
<PossiblyUnusedReturnValue>
Expand Down Expand Up @@ -2327,14 +2301,6 @@
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/PhpInfoController.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/Preferences/ExportController.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
Expand Down Expand Up @@ -2537,11 +2503,6 @@
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/SchemaExportController.php">
<PossiblyUnusedReturnValue>
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/Server/BinlogController.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
Expand Down Expand Up @@ -3513,14 +3474,6 @@
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/Table/GetFieldController.php">
<PossiblyNullArgument>
<code><![CDATA[$result]]></code>
</PossiblyNullArgument>
<PossiblyUnusedReturnValue>
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/Table/GisVisualizationController.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
Expand All @@ -3537,9 +3490,6 @@
<PossiblyInvalidCast>
<code><![CDATA[$_GET['fileFormat']]]></code>
</PossiblyInvalidCast>
<PossiblyUnusedReturnValue>
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
<RiskyCast>
<code><![CDATA[$_POST['pos'] ?? $_GET['pos'] ?? $_SESSION['tmpval']['pos']]]></code>
<code><![CDATA[$_POST['session_max_rows'] ?? $_GET['session_max_rows']]]></code>
Expand Down Expand Up @@ -4206,9 +4156,6 @@
<code><![CDATA[$toggleActivation]]></code>
<code><![CDATA[$version]]></code>
</MixedAssignment>
<PossiblyUnusedReturnValue>
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/Table/ZoomSearchController.php">
<DeprecatedMethod>
Expand Down Expand Up @@ -4382,11 +4329,6 @@
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/Controllers/VersionCheckController.php">
<PossiblyUnusedReturnValue>
<code><![CDATA[Response|null]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/View/CreateController.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
Expand Down Expand Up @@ -12955,6 +12897,11 @@
<code><![CDATA[$config->settings]]></code>
</InvalidPropertyAssignmentValue>
</file>
<file src="tests/unit/Controllers/PhpInfoControllerTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
</file>
<file src="tests/unit/Controllers/Server/BinlogControllerTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
Expand Down
1 change: 1 addition & 0 deletions resources/templates/javascript/redirect.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
window.location = '{{ url|escape('js') }}';
};
</script>
{{ t('Taking you to the target site.') }}
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function run(bool $isSetupPage = false): void
$requestHandler->add(new RequestProblemChecking($this->template, $this->responseFactory));
$requestHandler->add(new CurrentServerGlobalSetting($this->config));
$requestHandler->add(new ThemeInitialization());
$requestHandler->add(new UrlRedirection($this->config));
$requestHandler->add(new UrlRedirection($this->config, $this->template, $this->responseFactory));
$requestHandler->add(new SetupPageRedirection($this->config, $this->responseFactory));
$requestHandler->add(new MinimumCommonRedirection($this->config, $this->responseFactory));
$requestHandler->add(new LanguageAndThemeCookieSaving($this->config));
Expand Down
38 changes: 19 additions & 19 deletions src/Controllers/ChangeLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

use PhpMyAdmin\Config;
use PhpMyAdmin\Core;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;

use function __;
Expand All @@ -20,20 +22,26 @@
use function ob_get_clean;
use function ob_start;
use function preg_replace;
use function printf;
use function readgzfile;
use function sprintf;
use function str_ends_with;

final class ChangeLogController implements InvocableController
{
public function __construct(private readonly ResponseRenderer $response, private readonly Config $config)
{
public function __construct(
private readonly ResponseRenderer $response,
private readonly Config $config,
private readonly ResponseFactory $responseFactory,
private readonly Template $template,
) {
}

public function __invoke(ServerRequest $request): Response|null
public function __invoke(ServerRequest $request): Response
{
$this->response->disable();
$this->response->getHeader()->sendHttpHeaders();
$response = $this->responseFactory->createResponse();
foreach ($this->response->getHeader()->getHttpHeaders() as $name => $value) {
$response = $response->withHeader($name, $value);
}

$filename = $this->config->getChangeLogFilePath();

Expand All @@ -42,16 +50,12 @@ public function __invoke(ServerRequest $request): Response|null
*/
// Check if the file is available, some distributions remove these.
if (! @is_readable($filename)) {
printf(
__(
'The %s file is not available on this system, please visit %s for more information.',
),
return $response->write(sprintf(
__('The %s file is not available on this system, please visit %s for more information.'),
basename($filename),
'<a href="' . Core::linkURL('https://www.phpmyadmin.net/')
. '" rel="noopener noreferrer" target="_blank">phpmyadmin.net</a>',
);

return null;
));
}

// Test if the file is in a compressed format
Expand Down Expand Up @@ -109,12 +113,8 @@ public function __invoke(ServerRequest $request): Response|null
'/a href="/' => 'a target="_blank" rel="noopener noreferrer" href="',
];

$this->response->addHeader('Content-Type', 'text/html; charset=utf-8');

$this->response->render('changelog', [
return $response->write($this->template->render('changelog', [
'changelog' => preg_replace(array_keys($replaces), $replaces, $changelog),
]);

return null;
]));
}
}