This commit is contained in:
2019-01-14 16:50:21 +01:00
parent 22fc7cfe22
commit 94fa0c2870
7 changed files with 108 additions and 174 deletions

View File

@ -1,31 +1,45 @@
<?php
/**
* classe pour gerer le routage des pages
* la variable static $router sert a utiliser le router dans plusieurs fichier
* sans forcement avoir une obligation de nom de variable
* de plus ils sert a garder une route unique
*/
class Router {
//variable static pour stocker le router
private static $router;
//definit le router
public function __construct() {
//TODO faire que si un router existe daj<61> retourner le routeur existant
Router::$router = $this;
}
//fonction static pour recuperer un router d<>j<EFBFBD> cr<63><72>
public static function getRouter() {
return Router::$router;
}
//liste des routes
private $routeList = array();
//ajout d'une route
public function addRoute($route, $page) {
$this->routeList[$route] = $page;
}
public function dump() {
return $this->routeList;
}
//fonction de recherche d'une route par rapport a un texte
//return function
public function search($path) {
foreach ($this->routeList as $reg => $page) {
if(preg_match($reg, $path)) {
return $page;
}
}
return function() {return file_get_contents("../html/404.html");};
return function () {
return file_get_contents("../html/404.html");
};
}
}