Optimized routing

This commit is contained in:
Kevin Frantz 2018-07-14 19:07:23 +02:00
parent d966cbc35d
commit 5c5eb64fd8
4 changed files with 36 additions and 10 deletions

View File

@ -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();
?>

View File

@ -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']) {

View File

@ -12,12 +12,6 @@ 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
View 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.'&';
}
}
}