do not use app container in classes
soko-web/pipeline/pr-master This commit looks good

This commit is contained in:
bence committed 2023-04-19 23:26:24 +02:00
1 parent 0f87a9c6e3
commit 4fe463fcc5
9 files changed
+68 -31

No files matched your search

+12 -3
View File
@@ -64,7 +64,7 @@ class HttpResponse
list($route, $params) = $match;
$this->request->setParsedRouteParams($params);
$handler = $route->getHandler();
$controller = new $handler[0]($this->request);
$controller = new $handler[0]();
if (
$controller instanceof IAuthenticationRequired &&
@@ -103,7 +103,7 @@ class HttpResponse
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
$response->render();
} elseif ($response instanceof IRedirect) {
header('Location: ' . $response->getUrl(), true, $response->getHttpCode());
header('Location: ' . $this->getRedirectUrl($response), true, $response->getHttpCode());
} else {
$this->render404();
}
@@ -113,7 +113,7 @@ class HttpResponse
{
$this->request->session()->set('redirect_after_login', $this->rawUrl);
$response = new Redirect($this->routeCollection->getRoute($this->appConfig['loginRouteId'])->generateLink(), IRedirect::TEMPORARY);
header('Location: ' . $response->getUrl(), true, $response->getHttpCode());
header('Location: ' . $this->getRedirectUrl($response), true, $response->getHttpCode());
}
private function renderAntiCsrfError(): void
@@ -142,4 +142,13 @@ class HttpResponse
header('Content-Type: text/html; charset=UTF-8', true, 500);
$content->render();
}
private function getRedirectUrl(IRedirect $redirect): string
{
$url = $redirect->getTarget();
if (preg_match('/^http(s)?/', $url) !== 1) {
$url = $this->request->getBase() . $url;
}
return $url;
}
}
+2 -8
View File
@@ -14,15 +14,9 @@ class Redirect implements IRedirect
$this->type = $type;
}
public function getUrl(): string
public function getTarget(): string
{
if (preg_match('/^http(s)?/', $this->target) === 1) {
$link = $this->target;
} else {
$link = \Container::$request->getBase() . $this->target;
}
return $link;
return $this->target;
}
public function getHttpCode(): int