mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-06-22 22:39:19 +00:00
ça'
This commit is contained in:
@ -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");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user