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 _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 getUsedMemory($initMemory, $method) { $finalMemory = memory_get_usage(); $size = $finalMemory - $initMemory; $peakUsage = memory_get_peak_usage(); $peakSize = $peakUsage - $initMemory; echo "<br />\n"; echo $method . ' memory used: ' . BFW_Func::convertMemorySize($size) . "<br />\n"; echo $method . ' peak memory used: ' . BFW_Func::convertMemorySize($peakSize) . "<br />\n"; echo "<br />\n"; }
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); }
public static function set($class) { if (!isset(self::$objArr[$class])) { try { $objDir = OBJECT_PATH . '/' . str_replace('_', '/', $class); $file = $objDir . '/Obj_' . $class . '.obj.php'; if (!file_exists($file)) { throw new Exception('The file "' . $file . '" not exists!' . "\n"); } self::$objArr[$class] = BFW_Func::apcNewClass('Obj_' . $class); self::$objArr[$class]->objDir = $objDir; } catch (Exception $e) { exit($e->getMessage()); } } return self::$objArr[$class]; }
public function __call($method, $params) { try { $class = get_class($this) . '_' . ucfirst($method); if (!isset(self::$objArr[$class])) { $file = $this->objDir . '/' . $class . '.obj.php'; if (!file_exists($file)) { throw new Exception('The file "' . $file . '" not exists!' . "\n"); } require_once $file; self::$objArr[$class] = BFW_Func::apcNewClass($class); foreach ($this as $key => $val) { self::$objArr[$class]->{$key} = $val; } } call_user_func_array(array(self::$objArr[$class], 'run'), $params); } catch (Exception $e) { die($e->getMessage()); } }