MAPG-69 make Redirect able to redirect to external sources
This commit is contained in:
parent
295570a28d
commit
99c72d99be
@ -40,7 +40,7 @@ if ($match !== null) {
|
||||
|
||||
return;
|
||||
} elseif ($response instanceof MapGuesser\Interfaces\Response\IRedirect) {
|
||||
header('Location: ' . Container::$request->getBase() . '/' . $response->getUrl(), true, $response->getHttpCode());
|
||||
header('Location: ' . $response->getUrl(), true, $response->getHttpCode());
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ class HomeController
|
||||
{
|
||||
public function getIndex(): IRedirect
|
||||
{
|
||||
return new Redirect([\Container::$routeCollection->getRoute('maps'), []], IRedirect::TEMPORARY);
|
||||
return new Redirect(\Container::$routeCollection->getRoute('maps')->generateLink(), IRedirect::TEMPORARY);
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ use MapGuesser\Interfaces\Response\IRedirect;
|
||||
|
||||
class Redirect implements IRedirect
|
||||
{
|
||||
private $target;
|
||||
private string $target;
|
||||
|
||||
private int $type;
|
||||
|
||||
public function __construct($target, int $type = IRedirect::TEMPORARY)
|
||||
public function __construct(string $target, int $type = IRedirect::TEMPORARY)
|
||||
{
|
||||
$this->target = $target;
|
||||
$this->type = $type;
|
||||
@ -16,10 +16,10 @@ class Redirect implements IRedirect
|
||||
|
||||
public function getUrl(): string
|
||||
{
|
||||
if (is_array($this->target)) {
|
||||
$link = $this->target[0]->generateLink($this->target[1]);
|
||||
} else {
|
||||
if (preg_match('/^http(s)?/', $this->target)) {
|
||||
$link = $this->target;
|
||||
} else {
|
||||
$link = \Container::$request->getBase() . '/' . $this->target;
|
||||
}
|
||||
|
||||
return $link;
|
||||
|
Loading…
Reference in New Issue
Block a user