public static function set($key, $data) { $cache_key = self::gen_key($key); $sig = file_put_contents(self::$config['cache_path'] . 'cache_' . $cache_key, $data); if (!$sig) { FYTOOL::error_ctrl('can not write cache'); } }
/** * 热切换当前连接 * @param $sid 标记连接的唯一名字,可能是配置文件中定义的key,也可能是手动创建的连接 */ public static function select_conn($sid) { self::init(); if ($sid == '' || !isset(self::$conn_pool[$sid])) { FYTOOL::error_ctrl($sid . '未定义,或连接未创建。'); } else { self::$pdo = self::$conn_pool[$sid]; } }
/** * 调用Action的函数,在dispatcher里面调用, * @param 当前执行的Action名字,决定调用子类(具体action类)的哪个方法 * */ public function call($fun_name) { if (method_exists($this, $fun_name) || method_exists($this, '__call')) { $this->beforeAction(); $this->{$fun_name}(); $this->afterAction(); } else { FYTOOL::error_ctrl('Action未定义:' . $fun_name); } }
public static function init() { $conf = CONFIG::get('i18n'); self::$_dic_path = $conf['dic_path']; self::$_support_list = explode(',', trim($conf['support_list'], ',')); self::$_lang = self::_check_lang(); if (is_file(self::$_dic_path . self::$_lang . '.dic.php')) { self::$_dic = (include self::$_dic_path . self::$_lang . '.dic.php'); } else { if (is_dir(self::$_dic_path)) { //新建字典 copy(FYSCU_ROOT . 'dic/tpl.dic.php', self::$_dic_path . self::$_lang . '.dic.php'); } else { //新建目录 FYTOOL::r_copy(FYSCU_ROOT . 'core/modules/i18n/dic/', self::$_dic_path); copy(FYSCU_ROOT . 'dic/tpl.dic.php', self::$_dic_path . self::$_lang . '.dic.php'); } } }
public function action_license() { FYTOOL::debug($this->get_route()); $this->render('license'); }
if (is_array(CONFIG::get('modules'))) { include FYSCU_ROOT . './core/lib/action_base.class.php'; include FYSCU_ROOT . './core/lib/controller.class.php'; foreach (CONFIG::get('modules') as $k => $v) { //根据配置,引入相关的类文件,和相应功能文件 if ($v) { if (in_array($k, $FY_G['var']['component'])) { //do nothing } else { if (is_file(FYSCU_ROOT . './core/component/' . $k . '/' . $k . '.conf.php')) { CONFIG::add($k, include FYSCU_ROOT . './core/component/' . $k . '/' . $k . '.conf.php'); } include FYSCU_ROOT . './core/component/' . $k . '/' . $k . '.class.php'; FYTOOL::FY_set_global('component', $k); } } } } else { FYTOOL::error_ctrl('配置文件[组件配置]出错,请核对。'); } //控制器:URL路由 $controller = new controller(); $controller->dispatcher(); /* * 术语: * modules 组件 * controller 控制器 * mod 控制器处理类 * action 控制器处理类决定执行的行为 * */
private function display($tpl, $cache = 0) { if (empty(self::$config)) { self::$config = CONFIG::get('fytpl'); } if ($cache == 1) { //使用缓存 $filename = self::$config['tpl_path'] . 'c/' . md5($tpl) . '.php'; } else { //更新缓存 $name = self::$config['tpl_path'] . 'c/' . md5($tpl) . '.php'; if (self::$config['debug'] == 1) { $name = self::$config['tpl_path'] . 'c/' . 'debug_file.php'; } //die($name); $sig = file_put_contents($name, self::$output); self::$output = ''; if (!$sig) { echo '<meta http-equiv="content-type"content="text/html; charset=UTF-8"/>'; FYTOOL::debug('对不起,目录 ' . self::$config['tpl_path'] . 'c/ 不可写入,请检查文件权限。'); } $filename = $name; } return $filename; }
/** * 一切从这里开始~ * */ public function dispatcher() { //先判断是否存在这个类文件 if (is_file($this->_file_path)) { include $this->_file_path; //文件中是否定义了需要调用的CLASS if (class_exists($class = $this->_mod)) { //创建实例,并调用CALL函数,CALL函数在action的父类里定义 $action = new $class($this->_args); $action->call('action_' . $this->_action); } else { $msg = 'MOD CLASS 不存在:' . $this->_action; FYTOOL::error_ctrl($msg); } } else { $msg = 'MOD文件不存在:' . $this->_mod; FYTOOL::error_ctrl($msg); } }
public static function debug() { self::init(); $map = array(); FYTOOL::debug(self::findOne('loginfos', $map)); }