setSession(); $this->setControllerAndAction(); } /** * Function Description:执行程序 * Function Name: run * * * @author 倪宗锋 */ public function run() { $controller = $this->class;//控制器 $action = $this->action;//方法 /**==========执行控制器和方法==========**/ if (class_exists($controller)) {//如果控制器存在 $application = new $controller; if (method_exists($application, $action)) {//如果方法存在 $result = $application->$action(); } else { $result = Util::getErrUrlReturn(); } } else { $result = Util::getErrUrlReturn(); } echo $result; } /** * Function Description:设置路由的控制器class和action * Function Name: setControllerAndAction * * @return string * * @author 倪宗锋 */ public function setControllerAndAction() { /**==========从路由中获取控制器和方法名称==========**/ $routesConfig = $this->getRoutesConfig(); $requestUrl = parse_url($_SERVER['REQUEST_URI']); $url = $requestUrl['path']; $urlArr = explode('/', $url); $route = '/'; //通过循环匹配符合条件的路由 匹配成功循环不终止 foreach ($urlArr as $key => $urlVal) { $route = $route . '/' . $urlVal; $route = str_replace('//', '/', $route); if (empty($routesConfig[$route]) == false) {//如果路由在配置文件中则使用该配置 $routeArr = $routesConfig[$route]; $de_action = empty($urlArr[$key + 1]) ? $routeArr['de_action'] : $urlArr[$key + 1]; $this->class = $routeArr['controller'];//读取该配置的控制器 $this->action = $de_action . 'Action'; } } return ''; } /** * Function Description:获取模块的配置信息 * Function Name: getModelConfig * * @return array * * @author 倪宗锋 */ public function getRoutesConfig() { $key = 'frameWorkRoutesConfig'; $routesConfig = ApcCache::get($key);//获取路由配置并合并 if ($routesConfig == false) { $routesConfig = array(); $applicationConfig = require ROOT_PATH . '/config/application.config.php'; if (empty($applicationConfig['modules']) == false) { foreach ($applicationConfig['modules'] as $val) {//循环读取控制器文件合并 $filename = ROOT_PATH . "/$val/Config/model.config.php"; if (is_file($filename)) { $config = require $filename; $routesConfig = $routesConfig + $config; } } ApcCache::set($key, $routesConfig, 3600); } } return $routesConfig; } /** * Function Description:设置项目session * Function Name: setSession * * * @author 倪宗锋 */ private function setSession() { $config = Util::getSiteConfig(); session_start(); setcookie(session_name(), session_id(), time() + $config['session_life'], "/"); } /** * 项目关闭 */ protected function __destruct() { session_commit();//session数据提交 } }