mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-11-22 10:11:04 +01:00
Added draft for get routing
This commit is contained in:
parent
ceb83e20f1
commit
d966cbc35d
@ -15,8 +15,15 @@ abstract class AbstractController
|
||||
*/
|
||||
protected $core;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $post;
|
||||
|
||||
public function __construct(CoreInterface $core){
|
||||
$this->core = $core;
|
||||
$this->post = $_POST;
|
||||
}
|
||||
|
||||
protected function render(string $template,array $variables=[]):void{
|
||||
|
25
src/controller/order/Order.php
Normal file
25
src/controller/order/Order.php
Normal 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
|
||||
{}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ interface OrderInterface
|
||||
|
||||
public function addProduct():void;
|
||||
|
||||
public function showBasket():void;
|
||||
public function basket():void;
|
||||
|
||||
public function selectPaymentMethod():void;
|
||||
}
|
20
src/controller/product/Product.php
Normal file
20
src/controller/product/Product.php
Normal 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
|
||||
{}
|
||||
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ interface ProductInterface
|
||||
* but it's to abstract for this concrete exampl ;)
|
||||
* @param string $color
|
||||
*/
|
||||
public function filterByColor(string $color):void;
|
||||
public function colorFilter(string $color):void;
|
||||
|
||||
public function showAll():void;
|
||||
public function list():void;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ use controller\AbstractController;
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
final class Standart extends AbstractController
|
||||
final class Standart extends AbstractController implements StandartInterface
|
||||
{
|
||||
public function homepage():void{
|
||||
$this->render('standart/homepage.html.twig');
|
||||
|
13
src/controller/standart/StandartInterface.php
Normal file
13
src/controller/standart/StandartInterface.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace controller\standart;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
interface StandartInterface
|
||||
{
|
||||
public function homepage():void;
|
||||
}
|
||||
|
21
src/controller/user/User.php
Normal file
21
src/controller/user/User.php
Normal 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
|
||||
{}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ namespace router;
|
||||
|
||||
use core\CoreInterface;
|
||||
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
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var CoreInterface
|
||||
*/
|
||||
private $core;
|
||||
@ -23,46 +28,63 @@ final class Router implements RouterInterface
|
||||
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']){
|
||||
$this->postRouting();
|
||||
}
|
||||
if($this->get['router']){
|
||||
$this->getRouting();
|
||||
}else{
|
||||
$standart = new Standart($this->core);
|
||||
$standart->homepage();
|
||||
if ($this->get) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$standartController = new Standart($this->core);
|
||||
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
|
||||
{
|
||||
$this->get = $get;
|
||||
}
|
||||
|
||||
public function setCore(CoreInterface $core):void
|
||||
public function setCore(CoreInterface $core): void
|
||||
{
|
||||
$this->core = $core;
|
||||
}
|
||||
|
||||
public function setPost(array $post): void
|
||||
{
|
||||
$this->post = $post;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user