function ext_view_init(UnPHP $app, UnPHP_Dispatcher $dispatcher) { $conf = $app->getConfig(); if (isset($conf['view'])) { $c = $conf['view']; if (isset($c['themespath']) && isset($c['cachemode'])) { $themesPath = $c['themespath']; $cachemodeList = explode(",", $c['cachemode']); foreach ($cachemodeList as $mode) { if (isset($c[$mode])) { $modeConf = $c[$mode]; if (isset($modeConf['tempPath'])) { $newSmarty = "Ext_View_" . ucfirst($mode) . "Smarty"; $view = new $newSmarty(); if ($view->init($modeConf)) { $view->setScriptPath($themesPath); $dispatcher->setView($view); break; } } } } } } }
/** * 初始化框架 * @author Xiao Tangren <*****@*****.**> * @data 2014-03-05 */ private function init($confFile) { error_reporting(0); $this->iniLoadFile(); $this->_dispatcher = UnPHP_Dispatcher::getInstance(); try { $ReadConf = new Unphp_ReadConf($confFile); $this->_config = $ReadConf->get(); switch ($this->_config['app']['debug']) { case 1: error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR); break; case 2: error_reporting(E_ALL); default: error_reporting(0); } $this->_modules = isset($this->_config['app']['modules']) ? explode(",", $this->_config['app']['modules']) : array(); self::$_app = $this; // 注册“自动加载”接管函数 $this->registerAutoLoad(); $request = new UnPHP_Request_Http(); // 设置默认模块/控制器/方法 isset($this->_config['app']['default_module']) ? $request->setDefaultModule($this->_config['app']['default_module']) : $request->setDefaultModule('index'); isset($this->_config['app']['default_controller']) ? $request->setDefaultController($this->_config['app']['default_controller']) : $request->setDefaultController('index'); isset($this->_config['app']['default_action']) ? $request->setDefaultAction($this->_config['app']['default_action']) : $request->setDefaultModule('index'); $this->_dispatcher->setRequest($request); // 设置框架404异常页面 $this->_dispatcher->setErrorController(new UnPHP_Error($request)); $this->extInit(); } catch (Exception $exc) { $exc->getMsg($this->_config['app']['debug'], $this->_dispatcher->getErrorController()); } }
/** * 注册路由协议 * @author Xiao Tangren <*****@*****.**> * @param UnPHP $dispatcher */ public function _initRoute(UnPHP_Dispatcher $dispatcher) { $default_route = new UnPHP_Route_Simple("m", 'c', 'a'); $dispatcher->getRouter()->addRoute('simple', $default_route); }
/** * 实例化自生。 * @author Xiao Tangren <*****@*****.**> * @data 2014-03-05 * @return type */ public static function getInstance() { if (null == self::$_instance) { self::$_instance = new self(); } return self::$_instance; }