public static function newModle() { // $modArr = preg_split('/[_\/.]/', trim(BFW_Request::get($modTag) ? BFW_Request::get($modTag) : 'index')); $modArr = explode('.', trim(BFW_Request::get(MOD_TAG) ? BFW_Request::get(MOD_TAG) : 'index')); foreach ($modArr as $k => $v) { if (!trim($v)) { unset($modArr[$k]); } else { $modArr[$k] = ucfirst($v); } } $fun = end($modArr); if (isset($modArr[1])) { array_pop($modArr); } $mod = join('/', $modArr); try { $module = 'Mod_' . str_replace('/', '_', $mod); if (class_exists($module)) { $modClass = BFW_Func::apcNewClass($module); $modClass->modDir = MODULE_PATH . '/' . $mod; return $modClass; } } catch (Exception $e) { die($e->getMessage()); } }
private static function _page($totalRows, $perPage, $group) { $totalPage = ceil($totalRows / $perPage); $totalGroup = ceil($totalPage / $group); $pageId = BFW_Request::get('pageId'); $groupId = BFW_Request::get('groupId'); if (0 == $pageId) { $pageId = 1; } if (0 == $groupId) { $groupId = ceil($pageId / $group); } else { $pageId = ($groupId - 1) * $group + 1; } $limit = ($pageId - 1) * $perPage; $start = $limit; // if ($end >= self::$totalRows) $end = self::$totalRows; // $end = self::$totalRows; $page['limit'] = $limit; $page['start'] = $start; $page['pageId'] = $pageId; $page['groupId'] = $groupId; $page['totalPage'] = $totalPage; $page['totalGroup'] = $totalGroup; return $page; }
private static function _execute($sql, $params) { try { if (!self::$sqlDebug) { self::$sqlDebug = BFW_Request::get('sqlDebug'); } if (self::$sqlDebug) { $startTime = BFW_Func::getMicroTime(); } self::$sth = self::$pdo[self::$db]->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); self::$sth->execute($params); if (self::$sqlDebug) { $endTime = BFW_Func::getMicroTime(); $times = $endTime - $startTime; if (preg_match('/^SELECT/i', $sql)) { $sql = self::_getSelectSqlString($sql, $params); $explain = self::_getExpain('EXPLAIN ' . $sql); BFW_App::$appGlobal['sqlDebug'][self::$db][] = array('sql' => $sql, 'explain' => $explain, 'time' => number_format($times, 10)); } } } catch (PDOException $e) { $traceArr = $e->getTrace(); $content = '[' . date('Y-m-d H:i:s') . ']' . "\n"; foreach ($traceArr as $k => $v) { $content .= '# Error in file "' . $v['file'] . '" on line "' . $v['line'] . "\"\n"; } $content .= '# ' . $e->getMessage() . "\n" . '# SQL String: ' . $sql . "\n\n"; die($content); } }
public static function run() { $initMemory = memory_get_usage(); $mod = BFW_Request::get(MOD_TAG); if ($mod) { $modArr = explode('.', $mod); $module = end($modArr); } $method = strstr($mod, '.') ? $module : __FUNCTION__; $module = BFW_Controler::newModle(); if ($module) { $module->{$method}(); } self::_getSqlDebug(); self::_getIncludeFile(); BFW_Func::getUsedMemory($initMemory, get_class($module) . '::' . $method); }