listAction = ['visitor' => array('accueil','search','quote','login','singin'), 'user' => array('quiz','commentary','favorite','logout'), 'admin' => array('null')]; $dVueEreur = []; $router = new \AltoRouter(); $router->map('GET', '/', 'VisitorControler'); /* 'i' => '[0-9]++' 'a' => '[0-9A-Za-z]++' 'h' => '[0-9A-Fa-f]++' '*' => '.+?' '**' => '.++' '' => '[^/\.]++' */ $router->map('GET|POST', '/quote/[i:arg]?', 'VisitorControler'); $match = $router->match(); $action = NULL; if(!$match){ $dVueEreur[] = "Requette introuvable"; $this->vueErreur($dVueEreur); } else{ $controller=$match['target'] ?? null; $action=$match['params']['action'] ?? 'accueil'; //Si existe, on l’appelle if(!$this->ifExisteAction($action)){ $dVueEreur[] = "Action introuvable"; $this->vueErreur($dVueEreur); } $controller = '\\Controleur\\' . $controller; $controller = new $controller; if (is_callable(array($controller, $action))) { call_user_func_array(array($controller, $action), array($match['params'])); } } } private function ifExisteAction(string $action):bool { if( in_array($action , $this->listAction['admin']) || in_array($action , $this->listAction['user']) || in_array($action , $this->listAction['visitor']) ) { return true; } return false; } private function verifDroit(string $action):bool { if( in_array($action , $listAction['admin']) && $role == 'admin') return true; elseif( in_array($action , $listAction['user']) && ($role == 'admin' || $role == 'user') ) return true; elseif(in_array($action , $listAction['visitor']) && ($role == 'admin'|| $role == 'user'|| $role == 'visitor')) return true; return false; } private function vueErreur(array $dVueErreur){ global $vues; echo "{$dVueErreur[0]}"; require_once $vues['erreur']; } }