Exemple #1
0
 static function findroute()
 {
     $vars = array();
     $elts = array();
     router::$url = str_replace(_URL_ . '/', '', 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI']);
     foreach (router::$routes as $name => &$route) {
         if (preg_match($route['route'], router::$url)) {
             router::$route = $name;
             if (preg_match($route['route'], router::$url, $vars)) {
                 foreach ($vars as $k => $v) {
                     if (!is_numeric($k)) {
                         $elts[$k] = $v;
                     }
                 }
             }
             // si des droits on étais définis dans le router
             if (isset($route['rights'])) {
                 if (is_array($route['rights'])) {
                     // on contrôle si REQUEST_METHOD existe
                     if (isset($_SERVER['REQUEST_METHOD'])) {
                         $requestMethod = $_SERVER['REQUEST_METHOD'];
                         if (isset($route['rights'][$requestMethod])) {
                             $rights = $route['rights'][$requestMethod];
                         } else {
                             trigger_error("methode " . $requestMethod . " invalide", E_USER_ERROR);
                         }
                     } else {
                         trigger_error("REQUEST_METHOD obligatoire", E_USER_ERROR);
                     }
                 } else {
                     $rights = $route['rights'];
                 }
             } else {
                 $rights = false;
             }
             if (isset($route['module'])) {
                 router::CallController($route['module'], $elts, $rights);
             }
             if (isset($route['redirect'])) {
                 router::Redirect($route['redirect']);
             }
             break;
         }
     }
 }
Exemple #2
0
function url($url, $par = [])
{
    return router::url($url, $par);
}