Skip to content

Commit 4fc7322

Browse files
Merge pull request #18485 from MauricioFauth/exit-wrapper
Add a wrapper around the `exit` language construct
2 parents 1b2138b + 22c6a2f commit 4fc7322

34 files changed

Lines changed: 222 additions & 150 deletions

libraries/classes/Config/PageSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private function processPageSettings(FormDisplay $formDisplay, ConfigFile $cf):
9898
// reload page
9999
$response = ResponseRenderer::getInstance();
100100
Core::sendHeaderLocation($response->getSelfUrl());
101-
exit;
101+
$response->callExit();
102102
}
103103

104104
return $result;

libraries/classes/Controllers/AbstractController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ protected function checkParameters(array $params, bool $request = false): void
133133
$this->response->setRequestStatus(false);
134134
$this->response->addHTML(Message::error($errorMessage)->getDisplay());
135135

136-
if (! defined('TESTSUITE')) {
137-
exit;
138-
}
136+
$this->response->callExit();
139137
}
140138

141139
/** @psalm-param int<400,599> $statusCode */

libraries/classes/Controllers/Export/ExportController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function __invoke(ServerRequest $request): void
311311
/** @var DatabaseExportController $controller */
312312
$controller = Core::getContainerBuilder()->get(DatabaseExportController::class);
313313
$controller($request);
314-
exit;
314+
$this->response->callExit();
315315
}
316316
}
317317

libraries/classes/Controllers/Table/RelationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private function updateForForeignKeys(Table $table, array $options, array $relat
269269
if (isset($_POST['preview_sql'])) {
270270
Core::previewSQL($previewSqlData);
271271

272-
exit;
272+
$this->response->callExit();
273273
}
274274

275275
if (empty($displayQuery) || $seenError) {

libraries/classes/Controllers/Table/Structure/SaveController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function updateColumns(): bool
147147
if (isset($_POST['preview_sql'])) {
148148
Core::previewSQL($changes !== [] ? $sqlQuery : '');
149149

150-
exit;
150+
$this->response->callExit();
151151
}
152152

153153
$columnsWithIndex = $this->dbi

libraries/classes/Database/Events.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function handleEditor(): void
200200
}
201201

202202
$this->response->addJSON('tableType', 'events');
203-
exit;
203+
$this->response->callExit();
204204
}
205205
}
206206

@@ -508,7 +508,7 @@ private function sendEditor(string $mode, array|null $item, string $title, strin
508508
unset($_POST);
509509
}
510510

511-
exit;
511+
$this->response->callExit();
512512
}
513513

514514
$message = __('Error in processing request:') . ' ';
@@ -521,7 +521,7 @@ private function sendEditor(string $mode, array|null $item, string $title, strin
521521
if ($this->response->isAjax()) {
522522
$this->response->setRequestStatus(false);
523523
$this->response->addJSON('message', $message);
524-
exit;
524+
$this->response->callExit();
525525
}
526526

527527
echo $message->getDisplay();
@@ -549,7 +549,7 @@ public function export(): void
549549
$this->response->addJSON('message', $exportData);
550550
$this->response->addJSON('title', $title);
551551

552-
exit;
552+
$this->response->callExit();
553553
}
554554

555555
$output = '<div class="container">';
@@ -574,7 +574,7 @@ public function export(): void
574574
$this->response->setRequestStatus(false);
575575
$this->response->addJSON('message', $message);
576576

577-
exit;
577+
$this->response->callExit();
578578
}
579579

580580
$this->response->addHTML($message->getDisplay());

libraries/classes/Database/Routines.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function handleEditor(): void
134134
echo "\n\n<h2>" . $title . "</h2>\n\n" . $editor;
135135
}
136136

137-
exit;
137+
$this->response->callExit();
138138
}
139139

140140
$message = __('Error in processing request:') . ' ';
@@ -153,7 +153,7 @@ public function handleEditor(): void
153153
if ($this->response->isAjax()) {
154154
$this->response->setRequestStatus(false);
155155
$this->response->addJSON('message', $message);
156-
exit;
156+
$this->response->callExit();
157157
}
158158

159159
echo $message->getDisplay();
@@ -268,7 +268,7 @@ public function handleRequestCreateOrEdit(array $errors, string $db): array
268268
if (! $GLOBALS['message']->isSuccess()) {
269269
$this->response->setRequestStatus(false);
270270
$this->response->addJSON('message', $output);
271-
exit;
271+
$this->response->callExit();
272272
}
273273

274274
$routines = self::getDetails($this->dbi, $db, $_POST['item_type'], $_POST['item_name']);
@@ -283,7 +283,7 @@ public function handleRequestCreateOrEdit(array $errors, string $db): array
283283
$this->response->addJSON('insert', ! empty($routine));
284284
$this->response->addJSON('message', $output);
285285
$this->response->addJSON('tableType', 'routines');
286-
exit;
286+
$this->response->callExit();
287287
}
288288

289289
/**
@@ -1127,7 +1127,7 @@ private function handleExecuteRoutine(): void
11271127
if ($this->response->isAjax()) {
11281128
$this->response->setRequestStatus(false);
11291129
$this->response->addJSON('message', $message);
1130-
exit;
1130+
$this->response->callExit();
11311131
}
11321132

11331133
echo $message->getDisplay();
@@ -1237,14 +1237,14 @@ private function handleExecuteRoutine(): void
12371237
$this->response->setRequestStatus($message->isSuccess());
12381238
$this->response->addJSON('message', $message->getDisplay() . $output);
12391239
$this->response->addJSON('dialog', false);
1240-
exit;
1240+
$this->response->callExit();
12411241
}
12421242

12431243
echo $message->getDisplay() , $output;
12441244
if ($message->isError()) {
12451245
// At least one query has failed, so shouldn't
12461246
// execute any more queries, so we quit.
1247-
exit;
1247+
$this->response->callExit();
12481248
}
12491249

12501250
unset($_POST);
@@ -1280,7 +1280,7 @@ public function handleExecute(): void
12801280
echo $form;
12811281
}
12821282

1283-
exit;
1283+
$this->response->callExit();
12841284
}
12851285

12861286
if ($this->response->isAjax()) {
@@ -1294,7 +1294,7 @@ public function handleExecute(): void
12941294

12951295
$this->response->setRequestStatus(false);
12961296
$this->response->addJSON('message', $message);
1297-
exit;
1297+
$this->response->callExit();
12981298
}
12991299
}
13001300
}
@@ -1545,7 +1545,7 @@ public function export(): void
15451545
$this->response->addJSON('message', $exportData);
15461546
$this->response->addJSON('title', $title);
15471547

1548-
exit;
1548+
$this->response->callExit();
15491549
}
15501550

15511551
$output = '<div class="container">';
@@ -1573,7 +1573,7 @@ public function export(): void
15731573
$this->response->setRequestStatus(false);
15741574
$this->response->addJSON('message', $message);
15751575

1576-
exit;
1576+
$this->response->callExit();
15771577
}
15781578

15791579
$this->response->addHTML($message->getDisplay());

libraries/classes/DatabaseInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function query(
165165
// The following statement will exit
166166
Generator::mysqlDie($this->getError($connectionType), $query);
167167

168-
exit;
168+
ResponseRenderer::getInstance()->callExit();
169169
}
170170

171171
return $result;

libraries/classes/DbTableExists.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static function checkDatabase(string $db, bool $isTransformationWrapper)
4646
Message::error(__('No databases selected.')),
4747
);
4848

49-
exit;
49+
$response->callExit();
5050
}
5151

5252
$urlParams = ['reload' => 1];
@@ -65,7 +65,7 @@ private static function checkDatabase(string $db, bool $isTransformationWrapper)
6565

6666
Core::sendHeaderLocation('./index.php?route=/' . Url::getCommonRaw($urlParams, '&'));
6767

68-
exit;
68+
$response->callExit();
6969
}
7070

7171
private static function checkTable(string $db, string $table, bool $isTransformationWrapper): void
@@ -90,7 +90,7 @@ private static function checkTable(string $db, string $table, bool $isTransforma
9090
}
9191

9292
if ($isTransformationWrapper) {
93-
exit;
93+
ResponseRenderer::getInstance()->callExit();
9494
}
9595

9696
if ($table !== '') {
@@ -110,6 +110,6 @@ private static function checkTable(string $db, string $table, bool $isTransforma
110110
$controller = Core::getContainerBuilder()->get(SqlController::class);
111111
$controller(Common::getRequest());
112112

113-
exit;
113+
ResponseRenderer::getInstance()->callExit();
114114
}
115115
}

libraries/classes/ErrorHandler.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ public function addError(
300300
default:
301301
// FATAL error, display it and exit
302302
$this->dispFatalError($error);
303-
if (! defined('TESTSUITE')) {
304-
exit;
305-
}
306303
}
307304
}
308305

@@ -325,7 +322,7 @@ public function triggerError(string $errorInfo, int $errorNumber = E_USER_NOTICE
325322
*
326323
* @param Error $error the error
327324
*/
328-
protected function dispFatalError(Error $error): void
325+
protected function dispFatalError(Error $error): never
329326
{
330327
$response = ResponseRenderer::getInstance();
331328
if (! $response->headersSent()) {
@@ -337,9 +334,7 @@ protected function dispFatalError(Error $error): void
337334

338335
$response->addHTML($error->getDisplay());
339336
$response->addHTML('</body></html>');
340-
if (! defined('TESTSUITE')) {
341-
exit;
342-
}
337+
$response->callExit();
343338
}
344339

345340
/**

0 commit comments

Comments
 (0)