Example #1
0
 private static function scan($force = FALSE)
 {
     $found = FALSE;
     if (!self::$scanned || $force) {
         foreach (self::$routes as $priority => $routes) {
             if ($found) {
                 break;
             }
             foreach ($routes as $route) {
                 if ($found) {
                     break;
                 }
                 unset($ctrl, $redirect);
                 list($pattern, $replacement, $method, $source) = $route;
                 switch ($method) {
                     case self::ROUTE_STATIC:
                         if (URI_PATH === $pattern) {
                             $ctrl = $replacement;
                         }
                         break;
                     case self::ROUTE_PCRE:
                         if (preg_match($pattern, URI_PATH)) {
                             $ctrl = preg_replace($pattern, $replacement, URI_PATH);
                         }
                         break;
                     case self::REDIRECT_STATIC:
                         if (URI_PATH === $pattern) {
                             $redirect = $replacement;
                         }
                         break;
                     case self::REDIRECT_PCRE:
                         if (preg_match($pattern, URI_PATH)) {
                             $redirect = preg_replace($pattern, $replacement, URI_PATH);
                         }
                         break;
                 }
                 if (isset($ctrl) || isset($redirect)) {
                     if (isset($ctrl) && is_readable($ctrl)) {
                         self::$pattern = $pattern;
                         self::$ctrl = $ctrl;
                         self::$method = $method;
                         self::$source = $source;
                         $found = TRUE;
                     }
                 }
             }
         }
         if (!self::$ctrl && !isset($redirect) && substr(URI_PATH, -1) !== '/') {
             $redirect = URI_PATH . '/';
             if (strlen(URI_PARAM)) {
                 $redirect .= '?' . URI_PARAM;
             }
         }
         if (isset($redirect)) {
             header('Location: ' . $redirect);
             exit;
         }
         self::$scanned = !$force;
     }
 }