/** * 项目生成 */ public function action_generator() { //检查来源 if (!($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1')) { FYTOOL::error_ctrl('你所在的主机不允许调用此方法。'); } if (FYTOOL::get_gp_value('submit')) { //通过按钮提交 $path = realpath(FYSCU_ROOT . '/../'); $project = isset($_POST['project']) ? $_POST['project'] : ''; if ($project != '') { $project = str_replace(array('/', '\\'), '', $project); $path = $path . '/' . $project; if (!file_exists($path)) { //创建目录 $fp = mkdir($path); $sig = FYTOOL::r_copy(FYSCU_ROOT . './pro_tpl/', $path); $fp_fyscu = mkdir($path . '/fyscu'); $sig_core = FYTOOL::r_copy(FYSCU_ROOT . './core/', $path . '/fyscu/core'); $sig_init = copy(FYSCU_ROOT . './fyscu.init.php', $path . './fyscu/fyscu.init.php'); $sig_dic = FYTOOL::r_copy(FYSCU_ROOT . './dic/', $path . '/fyscu/dic'); $ct = file_get_contents($path . '/index.php'); $ct = str_replace('UNAME', $project, $ct); file_put_contents($path . '/index.php', $ct); } header('location:/' . $project); } } }
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); } }
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 控制器处理类决定执行的行为 * */
/** * 一切从这里开始~ * */ 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); } }