Example #1
0
 public static function setActive($path, $routes, $app = false)
 {
     $path = substr($path, 0, 1) != '/' ? String::glue('/', $path) : $path;
     $path = substr($path, -1) != '/' ? String::glue($path, '/') : $path;
     if (Request::get('app') && self::$cache && self::inTemp($path)) {
         $data = self::$temp[$path];
         self::active($data['params'], $data['path']);
         return;
     }
     $results = array();
     foreach ($routes as $route => $params) {
         $pattern = self::parseRoute($route);
         if ($route === trim($path, '/')) {
             $results = array($route);
             break;
         }
         if (preg_match_all($pattern['route'], $path, $matches)) {
             $results[] = $route;
             if (sizeof($matches) > 1) {
                 $size = sizeof($pattern['params']);
                 for ($i = 0; $i < $size; $i++) {
                     $routes[$route][$pattern['params'][$i]] = $matches[$i + 1][0];
                 }
             }
         }
     }
     if (sizeof($results) > 1) {
         $param = $routes[max($results)];
         $pathSet = max($results);
     } else {
         $param = $routes[$results[0]];
         $pathSet = $results[0];
     }
     if (Request::get('debug')) {
         var_dump($param);
     }
     self::$activeRule = $pathSet;
     if (Request::get('app') && self::$cache) {
         self::addTemp($path, array('params' => $param, 'path' => $pathSet));
     }
     if ($app) {
         if ($pathSet == '/' && $path != '/') {
             throw new Exception('', 404);
         }
     }
     self::active($param, $pathSet);
     //        sizeof($results) > 1 ? self::active($routes[max($results)],max($results)) : self::active($routes[$results[0]],$results[0]);
 }