|
|
@ -2,11 +2,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace controleur;
|
|
|
|
namespace controleur;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use model\AdminModel;
|
|
|
|
use vendor\AltoRouter;
|
|
|
|
use vendor\AltoRouter;
|
|
|
|
|
|
|
|
use controleur\UserControleur;
|
|
|
|
|
|
|
|
use controleur\AdminControleur;
|
|
|
|
|
|
|
|
require 'AltoRouter.php';
|
|
|
|
|
|
|
|
|
|
|
|
class FrontControleur
|
|
|
|
class FrontControleur
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public function __construct(){
|
|
|
|
public function __construct(){
|
|
|
|
$altoRouteur = new AltoRouter();
|
|
|
|
|
|
|
|
|
|
|
|
global $twig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$router = new AltoRouter();
|
|
|
|
|
|
|
|
$router->setBasePath('~/mapoint2/Tp/routeur/Srouteur');
|
|
|
|
|
|
|
|
$router->map('GET', '/', 'UserControler.php');
|
|
|
|
|
|
|
|
$router->map('GET|POST','/user/[a:action]?','UserControler.php');
|
|
|
|
|
|
|
|
$router->map('GET|POST','/admin/[a:action]?','AdminControler.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$match = $router->match();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$match) {
|
|
|
|
|
|
|
|
$dVueEreur[] = "Page doesn't exist";
|
|
|
|
|
|
|
|
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
$controller=$match['target'] ?? null;
|
|
|
|
|
|
|
|
$action=$match['params']['action'] ?? null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$controller = '\\controleur\\' . $controller;
|
|
|
|
|
|
|
|
$controller = new $controller;
|
|
|
|
|
|
|
|
if($controller == "\\Controler\\AdminControler.php"){
|
|
|
|
|
|
|
|
if (!AdminModel::isAdmin()){
|
|
|
|
|
|
|
|
echo $twig->render('Connection.html');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_callable(array($controller, $action))) {
|
|
|
|
|
|
|
|
call_user_func_array(array($controller, $action),
|
|
|
|
|
|
|
|
array($match['params']));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Error $error){
|
|
|
|
|
|
|
|
$dVueEreur[] = "Controller doesn't exist";
|
|
|
|
|
|
|
|
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|