private static function init() { session_start(); config::set('start_time', getmicrotime()); //加载配置文件 config::init(); //初始化pathinfo router::parse(); //加载语言文件 lang::setLang(config::get("default_lang", "chinese")); lang::init(); //更新内核 sf::update(); }
private static function parse_routes($path) { //过滤 $path = htmlspecialchars(ltrim($path, '/')); //是否需要获取token if (config::get('token_open', false) && config::get('parse_mode', 'PATH_INFO') == 'PATH_INFO') { $info = explode("/", trim(str_replace('?', '/', $path), "/")); self::$get['token'] = strstr($info[0], 'TK') ? array_shift($info) : getToken(); $path = implode('/', $info); } //解析PATH if ($path == '') { self::$get['controller'] = config::get("router.default_controller", 'welcome'); self::$get['method'] = config::get("router.default_method", 'index'); } else { if (config::get('parse_mode', 'PATH_INFO') == 'QUERY_STRING') { self::$get['controller'] = $_GET[config::get("controller_tag", "module")] ? $_GET[config::get("controller_tag", "module")] : config::get("router.default_controller", 'welcome'); self::$get['method'] = $_GET[config::get("method_tag", "act")] ? $_GET[config::get("method_tag", "act")] : config::get("router.default_method", 'index'); } else { $router = config::get("router.rule"); if (isset($router[$path])) { self::set_request(explode("/", $router[$path])); return; } foreach ((array) $router as $key => $val) { $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); if (preg_match('#^' . $key . '$#', $path)) { if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) { $val = preg_replace('#^' . $key . '$#', $val, $path); } self::set_request(explode('/', $val)); config::set("auto_create_html", true); //如果是为静态也面,则标记可以生成静态页面 return; } } self::set_request(explode('/', $path)); } } }