mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-12-22 23:25:03 +01:00
Optimized routing
This commit is contained in:
parent
d966cbc35d
commit
5c5eb64fd8
@ -7,7 +7,6 @@ require __DIR__. '/vendor/autoload.php';
|
||||
$core = new Core();
|
||||
$router = new Router();
|
||||
$router->setCore($core);
|
||||
$router->setPost($_POST);
|
||||
$router->setGet($_GET);
|
||||
$router->route();
|
||||
?>
|
||||
|
@ -35,7 +35,7 @@ final class Router implements RouterInterface
|
||||
* {@inheritdoc}
|
||||
* @see \router\RouterInterface::route()
|
||||
*/
|
||||
public function route(): void
|
||||
public function route()
|
||||
{
|
||||
if ($this->get) {
|
||||
switch ($this->get['controller']) {
|
||||
|
@ -11,13 +11,7 @@ use core\CoreInterface;
|
||||
interface RouterInterface
|
||||
{
|
||||
public function setCore(CoreInterface $core):void;
|
||||
|
||||
/**
|
||||
* Post parameters are used to save data
|
||||
* @param array $post
|
||||
*/
|
||||
public function setPost(array $post): void;
|
||||
|
||||
|
||||
/**
|
||||
* Get Parameters are used to request Data
|
||||
* @param array $get
|
||||
@ -26,6 +20,7 @@ interface RouterInterface
|
||||
|
||||
/**
|
||||
* Opens the controller
|
||||
* @return mixed
|
||||
*/
|
||||
public function route():void;
|
||||
public function route();
|
||||
}
|
||||
|
32
src/router/Url.php
Normal file
32
src/router/Url.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace router;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
class Url
|
||||
{
|
||||
/**
|
||||
* ArrayCollection would be nicer but I have to save time ;)
|
||||
* @var array
|
||||
*/
|
||||
private $parameters;
|
||||
|
||||
public function setParameters(array $parameters):void{
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
public function getUrl():string{
|
||||
return "index.php".$this->getParameters();
|
||||
}
|
||||
|
||||
private function getParameters():string{
|
||||
$parameters = '?';
|
||||
foreach ($parameters as $key=>$value){
|
||||
$parameters .= $key.'='.$value.'&';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user