示例#1
0
 /**
  * Tries to match one of the URL routes to the current URL, otherwise
  * execute the default function.
  * Sets the callback that needs to be returned
  *
  * @param string $request
  */
 private static function _run($request)
 {
     // Whether or not we have matched the URL to a route
     $matched_route = false;
     $request = '/' . $request;
     //make sure the request has a trailing slash
     $request = rtrim($request, '/') . '/';
     $request = str_replace("//", "/", $request);
     // Sort the array by priority
     ksort(self::$_routes);
     // Loop through each priority level
     foreach (self::$_routes as $priority => $routes) {
         // Loop through each route for this priority level
         foreach ($routes as $source => $destination) {
             // Does the routing rule match the current URL?
             if (preg_match($source, $request, $matches)) {
                 // A routing rule was matched
                 $matched_route = TRUE;
                 $attr = implode('/', array_intersect_key($matches, array_flip(array_filter(array_keys($matches), 'is_string'))));
                 self::$_attr = explode('/', trim($attr, '/'));
                 self::_set_callback($destination);
             }
         }
     }
     if (!$matched_route) {
         if ($request != '/') {
             self::_set_callback($request);
         }
     }
 }
示例#2
0
 /**
  * Tries to match one of the URL routes to the current URL, otherwise
  * execute the default function.
  * Sets the callback that needs to be returned
  *
  * @param string $request
  */
 private static function _run($request)
 {
     // Whether or not we have matched the URL to a route
     $matched_route = false;
     $request = '/' . $request;
     //make sure the request has a trailing slash
     $request = rtrim($request, '/') . '/';
     // Sort the array by priority
     ksort(self::$_routes);
     // Loop through each priority level
     foreach (self::$_routes as $priority => $routes) {
         // Loop through each route for this priority level
         foreach ($routes as $source => $destination) {
             // Does the routing rule match the current URL?
             if (preg_match($source, $request, $matches)) {
                 // A routing rule was matched
                 $matched_route = TRUE;
                 $attr = implode('/', array_intersect_key($matches, array_flip(array_filter(array_keys($matches), 'is_string'))));
                 self::$_attr = explode('/', trim($attr, '/'));
                 self::_set_callback($destination);
             }
         }
     }
     //if no match found, check if the url is valid
     if (!$matched_route && $request != '/') {
         self::_set_callback($request);
     }
     if ($request == '/') {
         self::_set_callback(configItem('site')['default_controller']);
     }
 }