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

@@ -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,58 +14,77 @@ use controller\standart\Standart;
*/
final class Router implements RouterInterface
{
/**
*
* @var CoreInterface
*/
private $core;
/**
*
*
* @var array
*/
private $get;
/**
*
* @var array
* 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()
*/
private $post;
public function route():void
public function route(): void
{
if($this->post['route']){
$this->postRouting();
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();
}
if($this->get['router']){
$this->getRouting();
}else{
$standart = new Standart($this->core);
$standart->homepage();
}
}
private function postRouting():void{
}
private function getRouting():void{
throw new \Exception('Route not found!');
}
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;
}
}