MAPG-86 refactor view-controller
This commit is contained in:
parent
b0b244712f
commit
88fe7b7a03
@ -1,8 +0,0 @@
|
|||||||
<?php namespace MapGuesser\Interfaces\Controller;
|
|
||||||
|
|
||||||
use MapGuesser\Interfaces\View\IView;
|
|
||||||
|
|
||||||
interface IController
|
|
||||||
{
|
|
||||||
public function run(): IView;
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php namespace MapGuesser\Interfaces\View;
|
<?php namespace MapGuesser\Interfaces\Response;
|
||||||
|
|
||||||
interface IView
|
interface IContent
|
||||||
{
|
{
|
||||||
public function &getData(): array;
|
public function &getData(): array;
|
||||||
|
|
12
src/Interfaces/Response/IRedirect.php
Normal file
12
src/Interfaces/Response/IRedirect.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php namespace MapGuesser\Interfaces\Response;
|
||||||
|
|
||||||
|
interface IRedirect
|
||||||
|
{
|
||||||
|
const PERMANENT = 1;
|
||||||
|
|
||||||
|
const TEMPORARY = 2;
|
||||||
|
|
||||||
|
public function getUrl(): string;
|
||||||
|
|
||||||
|
public function getHttpCode(): int;
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
<?php namespace MapGuesser\View;
|
<?php namespace MapGuesser\Response;
|
||||||
|
|
||||||
use MapGuesser\Interfaces\View\IView;
|
use MapGuesser\Interfaces\Response\IContent;
|
||||||
|
|
||||||
abstract class ViewBase implements IView
|
abstract class ContentBase implements IContent
|
||||||
{
|
{
|
||||||
protected array $data;
|
protected array $data;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php namespace MapGuesser\View;
|
<?php namespace MapGuesser\Response;
|
||||||
|
|
||||||
class HtmlView extends ViewBase
|
class HtmlContent extends ContentBase
|
||||||
{
|
{
|
||||||
private string $template;
|
private string $template;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php namespace MapGuesser\View;
|
<?php namespace MapGuesser\Response;
|
||||||
|
|
||||||
class JsonView extends ViewBase
|
class JsonContent extends ContentBase
|
||||||
{
|
{
|
||||||
public function __construct(array &$data = [])
|
public function __construct(array &$data = [])
|
||||||
{
|
{
|
41
src/Response/Redirect.php
Normal file
41
src/Response/Redirect.php
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user