Skip to content

Commit 4c98f9b

Browse files
Merge pull request #19159 from MauricioFauth/response-renderer-disable-removal
Remove the ResponseRenderer::disable() method
2 parents 797fe78 + 578ed90 commit 4c98f9b

15 files changed

Lines changed: 453 additions & 205 deletions

‎app/services_controllers.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@
369369
],
370370
Export\ExportController::class => [
371371
'class' => Export\ExportController::class,
372-
'arguments' => ['$response' => '@response', '$export' => '@export'],
372+
'arguments' => ['@response', '@export', '@' . ResponseFactory::class],
373373
],
374374
Export\TablesController::class => [
375375
'class' => Export\TablesController::class,

‎phpstan-baseline.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7215,11 +7215,6 @@ parameters:
72157215
count: 1
72167216
path: src/Export/Export.php
72177217

7218-
-
7219-
message: "#^Method PhpMyAdmin\\\\Export\\\\Export\\:\\:getMemoryLimit\\(\\) should return int but returns \\(float\\|int\\)\\.$#"
7220-
count: 1
7221-
path: src/Export/Export.php
7222-
72237218
-
72247219
message: "#^Only booleans are allowed in a negated boolean, int\\|false given\\.$#"
72257220
count: 1

‎psalm-baseline.xml‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,7 @@
18141814
<code><![CDATA[$whatStrucOrData]]></code>
18151815
</PossiblyInvalidArgument>
18161816
<PossiblyInvalidCast>
1817+
<code><![CDATA[$this->export->dumpBuffer]]></code>
18171818
<code><![CDATA[$this->export->dumpBuffer]]></code>
18181819
<code><![CDATA[$whatStrucOrData]]></code>
18191820
<code><![CDATA[$whatStrucOrData]]></code>
@@ -1844,13 +1845,6 @@
18441845
<code><![CDATA[$GLOBALS['export_type']]]></code>
18451846
<code><![CDATA[$GLOBALS['export_type']]]></code>
18461847
</PossiblyNullArgument>
1847-
<PossiblyUnusedReturnValue>
1848-
<code><![CDATA[Response|null]]></code>
1849-
</PossiblyUnusedReturnValue>
1850-
<RedundantCondition>
1851-
<code><![CDATA[! $GLOBALS['save_on_server']]]></code>
1852-
<code><![CDATA[$outputFormat === 'sendit' && ! $GLOBALS['save_on_server']]]></code>
1853-
</RedundantCondition>
18541848
<RiskyTruthyFalsyComparison>
18551849
<code><![CDATA[$asSeparateFiles]]></code>
18561850
<code><![CDATA[$onServerParam]]></code>
@@ -5737,12 +5731,6 @@
57375731
<code><![CDATA[$GLOBALS['time_start']]]></code>
57385732
<code><![CDATA[$GLOBALS['xkana']]]></code>
57395733
</InvalidArrayOffset>
5740-
<InvalidReturnStatement>
5741-
<code><![CDATA[$memoryLimit]]></code>
5742-
</InvalidReturnStatement>
5743-
<InvalidReturnType>
5744-
<code><![CDATA[int]]></code>
5745-
</InvalidReturnType>
57465734
<MixedArgument>
57475735
<code><![CDATA[$GLOBALS['xkana'] ?? '']]></code>
57485736
<code><![CDATA[$dbAlias]]></code>
@@ -13673,7 +13661,6 @@
1367313661
<code><![CDATA[Config::getInstance()]]></code>
1367413662
<code><![CDATA[Config::getInstance()]]></code>
1367513663
<code><![CDATA[Config::getInstance()]]></code>
13676-
<code><![CDATA[Config::getInstance()]]></code>
1367713664
</DeprecatedMethod>
1367813665
<InaccessibleProperty>
1367913666
<code><![CDATA[$config->config->debug->sql]]></code>

‎src/Controllers/Export/ExportController.php‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpMyAdmin\Encoding;
1414
use PhpMyAdmin\Exceptions\ExportException;
1515
use PhpMyAdmin\Export\Export;
16+
use PhpMyAdmin\Http\Factory\ResponseFactory;
1617
use PhpMyAdmin\Http\Response;
1718
use PhpMyAdmin\Http\ServerRequest;
1819
use PhpMyAdmin\Identifiers\DatabaseName;
@@ -39,8 +40,11 @@
3940

4041
final class ExportController implements InvocableController
4142
{
42-
public function __construct(private readonly ResponseRenderer $response, private readonly Export $export)
43-
{
43+
public function __construct(
44+
private readonly ResponseRenderer $response,
45+
private readonly Export $export,
46+
private readonly ResponseFactory $responseFactory,
47+
) {
4448
}
4549

4650
public function __invoke(ServerRequest $request): Response|null
@@ -164,14 +168,6 @@ public function __invoke(ServerRequest $request): Response|null
164168
}
165169
}
166170

167-
/**
168-
* If we are sending the export file (as opposed to just displaying it
169-
* as text), we have to bypass the usual PhpMyAdmin\Response mechanism
170-
*/
171-
if ($outputFormat === 'sendit' && ! $GLOBALS['save_on_server']) {
172-
$this->response->disable();
173-
}
174-
175171
$tableNames = [];
176172
// Generate error url and check for needed variables
177173
if ($GLOBALS['export_type'] === 'server') {
@@ -546,9 +542,7 @@ public function __invoke(ServerRequest $request): Response|null
546542
return null;
547543
}
548544

549-
echo $this->export->dumpBuffer;
550-
551-
return null;
545+
return $this->responseFactory->createResponse()->write($this->export->dumpBuffer);
552546
}
553547

554548
/**

‎src/Export/Export.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function getMemoryLimit(): int
276276
// Some memory is needed for compression, assume 1/3
277277
$memoryLimit /= 8;
278278

279-
return $memoryLimit;
279+
return (int) $memoryLimit;
280280
}
281281

282282
/**

‎src/Footer.php‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ class Footer
3737
* or also include scripts, errors and links
3838
*/
3939
private bool $isMinimal = false;
40-
/**
41-
* Whether to display anything
42-
*/
43-
private bool $isEnabled = true;
4440

4541
public function __construct(private readonly Template $template, private readonly Config $config)
4642
{
@@ -155,14 +151,6 @@ public function getErrorMessages(): string
155151
return $retval;
156152
}
157153

158-
/**
159-
* Disables the rendering of the footer
160-
*/
161-
public function disable(): void
162-
{
163-
$this->isEnabled = false;
164-
}
165-
166154
/**
167155
* Set the ajax flag to indicate whether
168156
* we are servicing an ajax request
@@ -197,10 +185,6 @@ public function getScripts(): Scripts
197185
*/
198186
public function getDisplay(): string
199187
{
200-
if (! $this->isEnabled) {
201-
return '';
202-
}
203-
204188
if (! $this->isAjax && ! $this->isMinimal) {
205189
if (Core::getEnv('SCRIPT_NAME') !== '') {
206190
$url = $this->getSelfUrl();

‎src/Header.php‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ class Header
5959
* Whether we are servicing an ajax request.
6060
*/
6161
private bool $isAjax = false;
62-
/**
63-
* Whether to display anything
64-
*/
65-
private bool $isEnabled = true;
6662
/**
6763
* Whether the HTTP headers (and possibly some HTML)
6864
* have already been sent to the browser
@@ -163,14 +159,6 @@ public function getJsParamsCode(): string
163159
return 'window.Navigation.update(window.CommonParams.setAll(' . json_encode($params, JSON_HEX_TAG) . '));';
164160
}
165161

166-
/**
167-
* Disables the rendering of the header
168-
*/
169-
public function disable(): void
170-
{
171-
$this->isEnabled = false;
172-
}
173-
174162
/**
175163
* Set the ajax flag to indicate whether
176164
* we are servicing an ajax request
@@ -247,7 +235,7 @@ public function disableWarnings(): void
247235
*/
248236
public function getDisplay(): string
249237
{
250-
if ($this->headerIsSent || ! $this->isEnabled || $this->isAjax) {
238+
if ($this->headerIsSent || $this->isAjax) {
251239
return '';
252240
}
253241

‎src/Plugins/Auth/AuthenticationCookie.php‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
namespace PhpMyAdmin\Plugins\Auth;
99

10+
use Fig\Http\Message\StatusCodeInterface;
1011
use PhpMyAdmin\Config;
1112
use PhpMyAdmin\Core;
1213
use PhpMyAdmin\Current;
1314
use PhpMyAdmin\Error\ErrorHandler;
1415
use PhpMyAdmin\Exceptions\AuthenticationFailure;
1516
use PhpMyAdmin\Exceptions\SessionHandlerException;
17+
use PhpMyAdmin\Http\Factory\ResponseFactory;
1618
use PhpMyAdmin\Http\Response;
1719
use PhpMyAdmin\LanguageManager;
1820
use PhpMyAdmin\Message;
@@ -478,10 +480,11 @@ public function rememberCredentials(): Response|null
478480
Util::clearUserCache();
479481

480482
$responseRenderer = ResponseRenderer::getInstance();
481-
$responseRenderer->disable();
482-
$responseRenderer->redirect('./index.php?route=/' . Url::getCommonRaw($urlParams, '&'));
483483

484-
return $responseRenderer->response();
484+
return ResponseFactory::create()->createResponse(StatusCodeInterface::STATUS_FOUND)->withHeader(
485+
'Location',
486+
$responseRenderer->fixRelativeUrlForRedirect('./index.php?route=/' . Url::getCommonRaw($urlParams, '&')),
487+
);
485488
}
486489

487490
/**

‎src/Plugins/Auth/AuthenticationSignon.php‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace PhpMyAdmin\Plugins\Auth;
99

10+
use Fig\Http\Message\StatusCodeInterface;
1011
use PhpMyAdmin\Config;
1112
use PhpMyAdmin\Exceptions\AuthenticationFailure;
13+
use PhpMyAdmin\Http\Factory\ResponseFactory;
1214
use PhpMyAdmin\Http\Response;
1315
use PhpMyAdmin\LanguageManager;
1416
use PhpMyAdmin\Plugins\AuthenticationPlugin;
@@ -40,7 +42,6 @@ class AuthenticationSignon extends AuthenticationPlugin
4042
public function showLoginForm(): Response
4143
{
4244
$responseRenderer = ResponseRenderer::getInstance();
43-
$responseRenderer->disable();
4445
unset($_SESSION['LAST_SIGNON_URL']);
4546
$config = Config::getInstance();
4647
if (empty($config->selectedServer['SignonURL'])) {
@@ -53,9 +54,10 @@ public function showLoginForm(): Response
5354
return $responseRenderer->response();
5455
}
5556

56-
$responseRenderer->redirect($config->selectedServer['SignonURL']);
57-
58-
return $responseRenderer->response();
57+
return ResponseFactory::create()->createResponse(StatusCodeInterface::STATUS_FOUND)->withHeader(
58+
'Location',
59+
$responseRenderer->fixRelativeUrlForRedirect($config->selectedServer['SignonURL']),
60+
);
5961
}
6062

6163
/**

‎src/ResponseRenderer.php‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ class ResponseRenderer
5151
* Whether we are servicing an ajax request.
5252
*/
5353
protected bool $isAjax = false;
54-
/**
55-
* Whether response object is disabled
56-
*/
57-
protected bool $isDisabled = false;
5854
/**
5955
* Whether there were any errors during the processing of the request
6056
* Only used for ajax responses
@@ -205,17 +201,6 @@ public function isAjax(): bool
205201
return $this->isAjax;
206202
}
207203

208-
/**
209-
* Disables the rendering of the header
210-
* and the footer in responses
211-
*/
212-
public function disable(): void
213-
{
214-
$this->header->disable();
215-
$this->footer->disable();
216-
$this->isDisabled = true;
217-
}
218-
219204
/**
220205
* Returns a PhpMyAdmin\Header object
221206
*/
@@ -273,11 +258,6 @@ private function getDisplay(): string
273258
*/
274259
private function ajaxResponse(): string
275260
{
276-
/* Avoid wrapping in case we're disabled */
277-
if ($this->isDisabled) {
278-
return $this->getDisplay();
279-
}
280-
281261
if (! isset($this->JSON['message'])) {
282262
$this->JSON['message'] = $this->getDisplay();
283263
} elseif ($this->JSON['message'] instanceof Message) {

0 commit comments

Comments
 (0)