91 lines
2.5 KiB
PHP
Raw Normal View History

2018-07-14 17:22:28 +02:00
<?php
namespace router;
use core\CoreInterface;
2018-07-14 17:48:24 +02:00
use controller\standart\Standart;
2018-07-14 18:50:47 +02:00
use controller\user\User;
use controller\product\Product;
use controller\order\Order;
2018-07-14 17:22:28 +02:00
/**
*
* @author kevinfrantz
*
*/
final class Router implements RouterInterface
{
2018-07-14 18:50:47 +02:00
2018-07-14 17:48:24 +02:00
/**
2018-07-14 18:50:47 +02:00
*
2018-07-14 17:48:24 +02:00
* @var CoreInterface
*/
private $core;
2018-07-14 18:50:47 +02:00
2018-07-14 17:48:24 +02:00
/**
2018-07-14 18:50:47 +02:00
*
2018-07-14 17:48:24 +02:00
* @var array
*/
private $get;
2018-07-14 18:50:47 +02:00
2018-07-14 17:48:24 +02:00
/**
2018-07-14 18:50:47 +02:00
* 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
*
* {@inheritdoc}
* @see \router\RouterInterface::route()
2018-07-14 17:48:24 +02:00
*/
2018-07-14 18:50:47 +02:00
public function route(): void
2018-07-14 17:22:28 +02:00
{
2018-07-14 18:50:47 +02:00
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();
2018-07-14 17:48:24 +02:00
}
2018-07-14 18:50:47 +02:00
throw new \Exception('Route not found!');
2018-07-14 17:22:28 +02:00
}
2018-07-14 18:50:47 +02:00
public function setGet(array $get): void
2018-07-14 17:48:24 +02:00
{
$this->get = $get;
}
2018-07-14 17:22:28 +02:00
2018-07-14 18:50:47 +02:00
public function setCore(CoreInterface $core): void
2018-07-14 17:48:24 +02:00
{
$this->core = $core;
}
2018-07-14 17:22:28 +02:00
}