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;
|
return;
|
||||||
} elseif ($response instanceof MapGuesser\Interfaces\Response\IRedirect) {
|
} 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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ class HomeController
|
|||||||
{
|
{
|
||||||
public function getIndex(): IRedirect
|
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
|
class Redirect implements IRedirect
|
||||||
{
|
{
|
||||||
private $target;
|
private string $target;
|
||||||
|
|
||||||
private int $type;
|
private int $type;
|
||||||
|
|
||||||
public function __construct($target, int $type = IRedirect::TEMPORARY)
|
public function __construct(string $target, int $type = IRedirect::TEMPORARY)
|
||||||
{
|
{
|
||||||
$this->target = $target;
|
$this->target = $target;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
@ -16,10 +16,10 @@ class Redirect implements IRedirect
|
|||||||
|
|
||||||
public function getUrl(): string
|
public function getUrl(): string
|
||||||
{
|
{
|
||||||
if (is_array($this->target)) {
|
if (preg_match('/^http(s)?/', $this->target)) {
|
||||||
$link = $this->target[0]->generateLink($this->target[1]);
|
|
||||||
} else {
|
|
||||||
$link = $this->target;
|
$link = $this->target;
|
||||||
|
} else {
|
||||||
|
$link = \Container::$request->getBase() . '/' . $this->target;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $link;
|
return $link;
|
||||||
|
Loading…
Reference in New Issue
Block a user