/** ---------------- 注册&初始化服务组件 ---------------- **/ //自动加载 DI()->loader = $loader; //配置 DI()->config = new PhalApi_Config_File(API_ROOT . '/Config'); //日记纪录 DI()->logger = new PhalApi_Logger_File(API_ROOT . '/Runtime', PhalApi_Logger::LOG_LEVEL_DEBUG | PhalApi_Logger::LOG_LEVEL_INFO | PhalApi_Logger::LOG_LEVEL_ERROR); //数据操作 - 基于NotORM,$_GET['__sql__']可自行改名 DI()->notorm = function () { $debug = !empty($_GET['__sql__']) ? true : false; return new PhalApi_DB_NotORM(DI()->config->get('dbs'), $debug); }; //调试模式,$_GET['__debug__']可自行改名 DI()->debug = !empty($_GET['__debug__']) ? true : DI()->config->get('sys.debug'); //翻译语言包设定 SL('zh_cn'); /** ---------------- 以下服务组件就根据需要定制注册 ---------------- **/ //缓存 - Memcached /** DI()->cache = function() { //根据Memcached是否加载 if(extension_loaded('memcached')){ $mc = new PhalApi_Cache_Memcached(DI()->config->get('sys.mc')); }else{ $mc = new PhalApi_Cache_Memcache(DI()->config->get('sys.mc')); } return $mc; }; */ DI()->cache = function () { $mc = new PhalApi_Cache_Memcache(DI()->config->get('sys.mc'));
protected function display($tpl = null) { $suffix = C('template-suffix'); $mood = $GLOBALS['_Module']; if (self::$is_smarty === true) { if (is_null($tpl)) { if (empty($this->act)) { $templates = Application::$act; } else { $templates = $this->act; } $temp = debug_backtrace(); if (isset($temp[1]['function']) && !empty($temp[1]['function'])) { $tpl = $temp[1]['function']; } elseif (!empty($this->method)) { $tpl = $this->method; } else { $tpl = Application::$mod; } unset($temp); } else { $arr = explode('/', $tpl); $cnt = count($arr); if ($cnt == 1) { //这种格式为index if (empty($this->act)) { $templates = Application::$act; } else { $templates = $this->act; } $tpl = $arr[0]; } elseif ($cnt == 2) { //这种格式为Index/index $templates = $arr[0]; $tpl = $arr[1]; } elseif ($cnt == 3) { //这种格式为Index/Index/index $mood = $arr[0]; $templates = $arr[1]; $tpl = $arr[2]; } else { //否则就出错了 SL('Template file format error', '设置的Template: ' . $tpl . ' format error', '访问日志', 1); if (APP_DEBUG) { die('Template file format error'); } } } $this->smarty->setTemplateDir(APP_TPL . $mood . DS . $templates . DS); spl_autoload_unregister('my_autoload'); $this->smarty->display($tpl . '.' . $suffix); } else { if (is_null($tpl)) { $tpl = $this->method; } $this->tpl = $tpl; if (Application::$act == $this->act && Application::$mod == $this->method) { Application::$tpl = $tpl; } else { $GLOBALS['_FileCount']++; return; } $content = file_get_contents(APP_TPL . $mood . DS . Application::$controller_obj->act . DS . Application::$tpl . '.' . $suffix); //parse include $ret = preg_match_all('/' . C('template-left_delimiter') . '\\s*include\\s*=\\s*"(.*?)"' . C('template-right_delimiter') . '/i', $content, $match); if ($ret) { foreach ($match[1] as $k => $v) { $tArr = explode('/', $v); $act_name = ucfirst($tArr[0] . 'Action'); $act_name = new $act_name(); $act_name->{$tArr}[1](); unset($tArr); } } if (is_array(Application::$controller_obj->valArr) && !empty(Application::$controller_obj->valArr)) { foreach (Application::$controller_obj->valArr as $k => $v) { ${$k} = $v; } unset(Application::$controller_obj->valArr); } $GLOBALS['_FileCount']++; require_once load_tpl(APP_TPL . $mood . DS . Application::$controller_obj->act . DS . Application::$tpl . '.' . $suffix, Application::$controller_obj->open_token); } }
function A($action, $params = array(), $type = 'Action') { if (empty($action) || !is_array($params)) { return false; } static $_cache_obj = array(); $mood = $GLOBALS['_Module']; $_cache_key = md5(md5($mood . $action . $type . serialize($params), true)); $_cache_value = $_cache_obj[$_cache_key]; if (isset($_cache_value) && is_object($_cache_value)) { return $_cache_value; } $arr = explode('\\', $action); $cnt = count($arr); if ($cnt == 1 || $cnt == 2) { $class = ucfirst($action) . $type; if ($cnt == 2) { $GLOBALS['_Module'] = ucfirst($arr[0]); $class = ucfirst($arr[1]) . $type; } if (!class_exists($class)) { if (APP_DEBUG) { die($type . ' class: ' . $class . ' not find. '); } else { //record log SL($type . ' not find', '访问的' . $type . ': ' . $class . ' class not find', '访问日志', 1); location(); } } if (is_array($params) && !empty($params)) { $params = array_values($params); $cnt = count($params); switch ($cnt) { case 1: $obj = new $class($params[0]); break; case 2: $obj = new $class($params[0], $params[1]); break; case 3: $obj = new $class($params[0], $params[1], $params[2]); break; case 4: $obj = new $class($params[0], $params[1], $params[2], $params[3]); break; case 5: $obj = new $class($params[0], $params[1], $params[2], $params[3], $params[4]); break; case 6: $obj = new $class($params[0], $params[1], $params[2], $params[3], $params[4], $params[5]); break; case 7: $obj = new $class($params[0], $params[1], $params[2], $params[3], $params[4], $params[5], $params[6]); break; case 8: $obj = new $class($params[0], $params[1], $params[2], $params[3], $params[4], $params[5], $params[6], $params[7]); break; default: if (APP_DEBUG) { die($type . ' class: ' . $class . ' construct function arguments too much,up to eight. '); } else { //record log SL($type . ' arguments', '访问的' . $type . ': ' . $class . ' construct function arguments too much,up to eight.', '访问日志', 1); location(); } break; } } else { $obj = new $class(); } $_cache_obj[$_cache_key] = $obj; if ($cnt == 2) { $GLOBALS['_Module'] = $mood; } unset($arr, $action, $params, $_cache_key, $mood); return $obj; } else { SL($type . ' format error', '设置的' . $type . ': ' . $action . ' format error', '访问日志', 1); if (APP_DEBUG) { die($action . ' format error'); } } }
/** * 这个是用来进行添加 删除 修改操作 使用事务操作 它是执行多条的 */ public function DDLExecutees($arr_sql, $data = array()) { if (!is_array($data) && !is_array($arr_sql)) { return false; } $res = array(); if (is_null($this->pdo)) { $this->connect(); } $this->free(); $this->pdo->beginTransaction(); //开启事务 try { for ($i = 0, $n = count($arr_sql); $i < $n; $i++) { if (!isset($data[$i])) { $data[$i] = array(); } if (!is_array($data[$i])) { SL('sql error', '执行sql: ' . $arr_sql[$i] . ' 发生错误,错误信息:传的参数不是数组 sql执行错误', 1); $this->pdo->rollBack(); //事务回滚 return false; } $this->execRes($data[$i], $arr_sql[$i]); $res[] = $this->lastInsID; } $this->pdo->commit(); //事务提交 return $res; } catch (Exception $e) { SL('sql error', '执行sql: ' . $sql . ' 发生错误,错误信息: ' . $e->getMessage() . 'sql执行错误', 1); $this->pdo->rollBack(); //事务回滚 return false; } return $res; }
private static function parseurl() { if (isset($_REQUEST['act']) && !empty($_REQUEST['act'])) { $act = ucfirst(trim($_REQUEST['act']) . 'Action'); } else { $act = 'IndexAction'; } if (isset($_REQUEST['mod']) && !empty($_REQUEST['mod'])) { $method = trim($_REQUEST['mod']); } else { $method = 'Index'; } if (CREATE_DEMO) { //if need create demo $demo = new Demo(); $demo->run(); } if (!class_exists($act)) { if (APP_DEBUG) { die('controller class: ' . $act . ' not find. '); } else { //record log SL('controller not find', '访问的controller: ' . $act . ' class not find', '访问日志', 1); location(); } } self::$controller_obj =& $controller; self::$act = str_ireplace('Action', '', $act); self::$mod = $method; $controller = new $act(); if (!method_exists($controller, $method)) { if (APP_DEBUG) { die('controller class: ' . $act . ', method: ' . $method . ' not find. '); } else { //record log SL('method not find', '访问的controller: ' . $act . ' class method: ' . $method . ' not find', '访问日志', 1); location(); } } $controller->method = $method; $controller->open_token = OPEN_TOKEN; $controller->act = self::$act; $controller->{$method}(); }
/** ---------------- 注册&初始化服务组件 ---------------- **/ //自动加载 DI()->loader = $loader; //配置 DI()->config = new PhalApi_Config_File(API_ROOT . '/Config'); //日记纪录 DI()->logger = new PhalApi_Logger_File(API_ROOT . '/Runtime', PhalApi_Logger::LOG_LEVEL_DEBUG | PhalApi_Logger::LOG_LEVEL_INFO | PhalApi_Logger::LOG_LEVEL_ERROR); //数据操作 - 基于NotORM,$_GET['__sql__']可自行改名 DI()->notorm = function () { $debug = !empty($_GET['__sql__']) ? true : false; return new PhalApi_DB_NotORM(DI()->config->get('dbs'), $debug); }; //调试模式,$_GET['__debug__']可自行改名 DI()->debug = !empty($_GET['__debug__']) ? true : DI()->config->get('sys.debug'); //翻译语言包设定 SL('en'); /** ---------------- 以下服务组件就根据需要定制注册 ---------------- **/ /** //缓存 - Memcached DI()->cache = function() { //根据Memcached是否加载 if(extension_loaded('memcached')){ $mc = new PhalApi_Cache_Memcached(DI()->config->get('sys.mc')); }else{ $mc = new PhalApi_Cache_Memcache(DI()->config->get('sys.mc')); } return $mc; }; */ /** //签名验证服务