Exemple #1
0
 /**
  * 	method:	finalise
  *
  * 	todo: write documentation
  */
 public static function finalise()
 {
     if (!self::$path) {
         trigger_error("There was no __WEBSITE_ROOT__ definition found, check your .htaccess file", E_USER_ERROR);
         return false;
     }
     self::$route = false;
     //	TODO: document better what this code does
     $static = self::getRouteByURL(self::$path);
     //	Find all the matches and store all the route names here
     $matches = array($static["src_selected"] => $static);
     //	NOTE: so every route passes through the callback, even though it doesnt ask for it??
     foreach (self::$callback as $c) {
         $data = call_user_func($c, self::$path);
         $route = $data ? self::getRoute($data["name"]) : false;
         if ($route) {
             $matches[$data["src_selected"]] = array_merge($route, $data);
         }
     }
     $matches = array_filter($matches);
     if (count($matches) == 1) {
         //	set the only result
         self::$route = current($matches);
     } else {
         //	If there was more than one match, we need to search for the longest one and discard the rest
         $longest = "";
         //	search for the longest match in the array
         foreach (Amslib_Array::valid($matches) as $k => $r) {
             if (strlen($k) > strlen($longest)) {
                 $longest = $k;
             }
         }
         self::$route = isset($matches[$longest]) ? $matches[$longest] : self::$emptyRoute;
     }
 }