This commit is contained in:
71 files changed
+7241
No files matched your search
@@ -0,0 +1,41 @@
|
||||
<?php namespace SokoWeb\Response;
|
||||
|
||||
use SokoWeb\Interfaces\Response\IRedirect;
|
||||
|
||||
class Redirect implements IRedirect
|
||||
{
|
||||
private string $target;
|
||||
|
||||
private int $type;
|
||||
|
||||
public function __construct(string $target, int $type = IRedirect::TEMPORARY)
|
||||
{
|
||||
$this->target = $target;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getUrl(): string
|
||||
{
|
||||
if (preg_match('/^http(s)?/', $this->target) === 1) {
|
||||
$link = $this->target;
|
||||
} else {
|
||||
$link = \Container::$request->getBase() . '/' . $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