MAPG-86 refactor view-controller
This commit is contained in:
1 parent
b0b244712f
commit
88fe7b7a03
7 files changed
+62
-17
No files matched your search
@@ -0,0 +1,41 @@
|
||||
<?php namespace MapGuesser\Response;
|
||||
|
||||
use MapGuesser\Interfaces\Response\IRedirect;
|
||||
|
||||
class Redirect implements IRedirect
|
||||
{
|
||||
private $target;
|
||||
|
||||
private int $type;
|
||||
|
||||
public function __construct($target, int $type = IRedirect::TEMPORARY)
|
||||
{
|
||||
$this->target = $target;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getUrl(): string
|
||||
{
|
||||
if (is_array($this->target)) {
|
||||
$link = $this->target[0]->generateLink($this->target[1]);
|
||||
} else {
|
||||
$link = $this->target;
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
public function getHttpCode(): int
|
||||
{
|
||||
switch ($this->type) {
|
||||
case IRedirect::PERMANENT:
|
||||
return 301;
|
||||
|
||||
case IRedirect::TEMPORARY:
|
||||
return 302;
|
||||
|
||||
default:
|
||||
return 302;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user