Added draft for get routing

This commit is contained in:
Kevin Frantz 2018-07-14 18:50:47 +02:00
parent ceb83e20f1
commit d966cbc35d
9 changed files with 144 additions and 36 deletions

View File

@ -15,8 +15,15 @@ abstract class AbstractController
*/ */
protected $core; protected $core;
/**
*
* @var array
*/
protected $post;
public function __construct(CoreInterface $core){ public function __construct(CoreInterface $core){
$this->core = $core; $this->core = $core;
$this->post = $_POST;
} }
protected function render(string $template,array $variables=[]):void{ protected function render(string $template,array $variables=[]):void{

View File

@ -0,0 +1,25 @@
<?php
namespace controller\order;
use controller\AbstractController;
/**
*
* @author kevinfrantz
*
*/
final class Order extends AbstractController implements OrderInterface
{
public function addProduct(): void
{}
public function store(): void
{}
public function basket(): void
{}
public function selectPaymentMethod(): void
{}
}

View File

@ -14,7 +14,7 @@ interface OrderInterface
public function addProduct():void; public function addProduct():void;
public function showBasket():void; public function basket():void;
public function selectPaymentMethod():void; public function selectPaymentMethod():void;
} }

View File

@ -0,0 +1,20 @@
<?php
namespace controller\product;
use controller\AbstractController;
/**
*
* @author kevinfrantz
*
*/
final class Product extends AbstractController implements ProductInterface
{
public function list(): void
{}
public function colorFilter(string $color): void
{}
}

View File

@ -12,8 +12,8 @@ interface ProductInterface
* but it's to abstract for this concrete exampl ;) * but it's to abstract for this concrete exampl ;)
* @param string $color * @param string $color
*/ */
public function filterByColor(string $color):void; public function colorFilter(string $color):void;
public function showAll():void; public function list():void;
} }

View File

@ -8,7 +8,7 @@ use controller\AbstractController;
* @author kevinfrantz * @author kevinfrantz
* *
*/ */
final class Standart extends AbstractController final class Standart extends AbstractController implements StandartInterface
{ {
public function homepage():void{ public function homepage():void{
$this->render('standart/homepage.html.twig'); $this->render('standart/homepage.html.twig');

View File

@ -0,0 +1,13 @@
<?php
namespace controller\standart;
/**
*
* @author kevinfrantz
*
*/
interface StandartInterface
{
public function homepage():void;
}

View File

@ -0,0 +1,21 @@
<?php
namespace controller\user;
/**
*
* @author kevinfrantz
*
*/
final class User implements UserInterface
{
public function logout(): void
{}
public function login(): void
{}
public function register(): void
{}
}

View File

@ -3,6 +3,9 @@ namespace router;
use core\CoreInterface; use core\CoreInterface;
use controller\standart\Standart; use controller\standart\Standart;
use controller\user\User;
use controller\product\Product;
use controller\order\Order;
/** /**
* *
@ -11,7 +14,9 @@ use controller\standart\Standart;
*/ */
final class Router implements RouterInterface final class Router implements RouterInterface
{ {
/** /**
*
* @var CoreInterface * @var CoreInterface
*/ */
private $core; private $core;
@ -23,30 +28,53 @@ final class Router implements RouterInterface
private $get; private $get;
/** /**
* All get Parameters should be visible in this function for overview reasons
* This Router uses switchs.
* It's not a good practice, but for this use case ok
* *
* @var array * {@inheritdoc}
* @see \router\RouterInterface::route()
*/ */
private $post;
public function route(): void public function route(): void
{ {
if($this->post['route']){ if ($this->get) {
$this->postRouting(); switch ($this->get['controller']) {
case 'user':
$userController = new User();
switch ($this->get['action']) {
case 'login':
return $userController->login();
case 'logout':
return $userController->logout();
case 'register':
return $userController->register();
}
case 'product':
$productController = new Product();
switch ($this->get['action']) {
case 'list':
return $productController->list();
case 'color':
return $productController->colorFilter($this->get['color']);
}
case 'order':
$orderController = new Order($this->core);
switch ($this->get['action']){
case 'store':
return $orderController->store();
case 'basket':
return $orderController->basket();
case 'payment':
return $orderController->selectPaymentMethod();
case 'add-product':
return $orderController->addProduct();
}
} }
if($this->get['router']){
$this->getRouting();
} else { } else {
$standart = new Standart($this->core); $standartController = new Standart($this->core);
$standart->homepage(); return $standartController->homepage();
} }
} throw new \Exception('Route not found!');
private function postRouting():void{
}
private function getRouting():void{
} }
public function setGet(array $get): void public function setGet(array $get): void
@ -58,11 +86,5 @@ final class Router implements RouterInterface
{ {
$this->core = $core; $this->core = $core;
} }
public function setPost(array $post): void
{
$this->post = $post;
}
} }