Skip to content

Commit

Permalink
Refactor the Routing::callSetupController() method
Browse files Browse the repository at this point in the history
Changes the method so it return a Response object when possible.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jul 27, 2023
1 parent fb39be0 commit 6597dee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 1 addition & 2 deletions libraries/classes/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ private function handle(ServerRequest $request): Response|null

if ($isSetupPage) {
$this->setupPageBootstrap($this->config);
Routing::callSetupController($request);

return null;
return Routing::callSetupController($request, $this->responseFactory);
}

return Routing::callControllerForRoute(
Expand Down
15 changes: 9 additions & 6 deletions libraries/classes/Routing/Routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,35 +176,38 @@ private static function isRoutesCacheFileValid(mixed $dispatchData): bool
&& $dispatchData[0]['GET']['/'] === HomeController::class;
}

public static function callSetupController(ServerRequest $request): void
public static function callSetupController(ServerRequest $request, ResponseFactory $responseFactory): Response|null
{
$route = $request->getRoute();
if ($route === '/setup' || $route === '/') {
(new MainController())($request);

return;
return null;
}

if ($route === '/setup/show-config') {
(new ShowConfigController())($request);

return;
return null;
}

if ($route === '/setup/validate') {
(new ValidateController())($request);

return;
return null;
}

echo (new Template())->render('error/generic', [
$response = $responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);
$response->getBody()->write((new Template())->render('error/generic', [
'lang' => $GLOBALS['lang'] ?? 'en',
'dir' => $GLOBALS['text_dir'] ?? 'ltr',
'error_message' => Sanitize::sanitizeMessage(sprintf(
__('Error 404! The page %s was not found.'),
'[code]' . htmlspecialchars($route) . '[/code]',
)),
]);
]));

return $response;
}

/**
Expand Down

0 comments on commit 6597dee

Please sign in to comment.