<?php /******************************** * 描述: Crontab入口示例文件 * 作者: heiyeluren * 创建: 2009-12-22 11:22 * 修改:2009-12-22 11:45 ********************************/ //定义基本路径常量 define("APP_DIR", str_replace("\\", "/", realpath(dirname(__FILE__) . "/.."))); //应用路径 define("TM_ROOT_DIR", str_replace("\\", "/", realpath(APP_DIR . "../../tmphp/"))); //框架路径 $confFile = APP_DIR . '/config/Config.ini'; //配置文件 //设定包含文件路径 set_include_path(get_include_path() . PATH_SEPARATOR . TMPHP_DIR); //包含基本入口文件和配置文件 require_once APP_DIR . '/config/AppConst.class.php'; require_once TM_ROOT_DIR . '/core/TM_Exception.class.php'; require_once TM_ROOT_DIR . '/tmphp.php'; //读取配置 $c = TM_Config::factory($confFile); $config = $c->getData(); //初始化数据库 $driver = $config['DataBase']['driver'] == '' ? "DB_Mysql" : $config['DataBase']['driver']; $class = TM_PREFIX . "_" . $driver; $dbConfig = array("host" => $config['DataBase']['host'], "user" => $config['DataBase']['user'], "pwd" => $config['DataBase']['pwd'], "db" => $config['DataBase']['db']); $db = new $class($dbConfig);
/** * 路由分发 * */ public function dispatch($configFile) { //不进行魔术过滤 set_magic_quotes_runtime(0); try { //设置配置文件 $config = TM_Config::factory($configFile); $arrConfig = $config->getData(); if (!empty($arrConfig)) { __save_config($arrConfig); } //读取控制器和action $route = self::parseUri($arrConfig); $controller = $route['ControllerName'] . "Controller"; $action = $route['ActionName'] . "Action"; //包含控制器文件 $controllerFile = APP_CONTROLLER_DIR . $controller . ".class.php"; if (!is_file($controllerFile) || !is_readable($controllerFile)) { throw new TM_Exception("controller file {$controllerFile} not exist or not readable"); } require $controllerFile; if (!class_exists($controller, false)) { throw new TM_Exception("controller class {$controller} not exist"); } //判断 Action $con = new $controller($arrConfig, $controller, $action); if (!method_exists($con, $action)) { throw new TM_Exception("controller class method {$controller}->{$action}() not exist"); } //设置时区 if (PHP_VERSION > '5.1.0') { @date_default_timezone_set($arrConfig['Common']['TimeZone']); } //进行Action操作 return $con->{$action}(); } catch (TM_Exception $exception) { throw $exception; } }