Example #1
0
 public static function dispatch()
 {
     // 分析PATHINFO信息
     if (!isset($_SERVER['PATH_INFO'])) {
         $_SERVER['PATH_INFO'] = '';
         $types = explode(',', 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL');
         foreach ($types as $type) {
             if (!empty($_SERVER[$type])) {
                 $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
                 break;
             }
         }
     }
     if ($url_str = $_SERVER['PATH_INFO']) {
         //取出伪静态扩展名 index.php/xx.html
         $part = pathinfo($_SERVER['PATH_INFO']);
         $url_ext = isset($part['extension']) ? strtolower($part['extension']) : '';
         if ($url_ext && ($allow_ext = App_Info::config('URL_SUFFIX_ALLOW'))) {
             //提取扩展名
             $allow = array_search($url_ext, $allow_ext);
             if ($allow !== false) {
                 App_Info::$URL_EXT = $url_ext;
                 $_SERVER['PATH_INFO'] = preg_replace('/.' . App_Info::$URL_EXT . '$/i', '', $_SERVER['PATH_INFO']);
                 $url_str = preg_replace('/.' . App_Info::$URL_EXT . '$/i', '', $url_str);
             }
         }
         $regx = trim($url_str, '/');
         $var = array();
         // 检测路由规则 如果没有则按默认规则调度URL
         if (!App_Info::config('URL_ROUTE_ON')) {
             self::decode_url_str($regx);
         } else {
             self::check_route($regx);
         }
     } else {
         //PATH_INFO 空
         $var = $_REQUEST;
         $con_val = App_Info::config('PATH_CONTROLLER_VAR');
         if (isset($var[$con_val])) {
             App_Info::$CONTROLLER_NAME = strip_tags($var[$con_val]);
             unset($var[$con_val]);
         }
         $act_val = App_Info::config('PATH_ACTION_VAR');
         if (isset($var[$act_val])) {
             App_Info::$ACTION_NAME = strip_tags($var[$act_val]);
             unset($var[$act_val]);
         }
     }
     App_Info::$CURRENT_URL_STR = App_Info::$CONTROLLER_NAME . '/' . App_Info::$ACTION_NAME . '?' . http_build_query($var);
 }