/** * 记录: * 使用默认的 loger 记录日志 * * 时间 - 服务器自动记录时间 * * 起因 - msg * 经过 * 结果 * * 地点 - sourceName * 人物 - userId * - actorName (userName) * * @param string $msg 记录的信息 * @param int $level * @param string $sourceName * @param string $actorName * @param string $actorId * @param mix $exts * @return boolean */ public static final function addLog($msg, $level = 0, $sourceName = "", $actorName = "", $actorId = "", $exts = null, $extsInt = null) { //如果禁用日志则不记录 by terry at Wed Aug 18 10:02:05 CST 2010 if (self::$_disabledAddLog) { return true; } if (is_array($msg)) { $msg = var_export($msg, true); } //默认所有日志就记录入 debuger 日志 self::getDefaultLogger()->log($msg, $level, $sourceName, $actorName, $actorId, $exts, $extsInt); if ($level > self::LEVEL_DEBUG) { //self::getDefaultLogger()->log( 'Before DB Log' ); self::getSystemLogger()->log($msg, $level, $sourceName, $actorName, $actorId, $exts, $extsInt); //self::getDefaultLogger()->log( 'After DB Log' ); } /** * 如果是Debug模式,同时输出到屏幕 / 判断debug模式在 addInfoToDefault 中实现 * @author terry * @version 0.1.0 * Mon Sep 24 21:06:25 CST 2007 */ Watt_Debug::addInfoToDefault('Watt_Log::addLog', $msg); return true; }
/** * 功能://添加新功能,用第二个参数来传所有的值 * Tony---Fri Mar 16 20:34:11 CST 2007----20:34:11 */ public function NewDb($sql, $he, $page = false, $type = '', $format1 = false) { Watt_Debug::addInfoToDefault('', 'startUseReadonlyDb'); Watt_Db::startUseReadonlyDb(); try { if ($format1) { $this->format = $format1; } else { $this->format = false; } $error_self = error_reporting(E_ALL ^ E_NOTICE); foreach ($he as $key => $v) { $title[$key] = $v[0]; if ($v[1]) { $field[$key] = $v[1]; } if ($v[2]) { $data[$key] = $v[2]; } if ($v[3]) { $field_t[$key] = $v[3]; } if ($v[4]) { $ti[$key] = $v[4]; } } if ($ti) { $this->addTot($ti, $this->heji_type); } $result = $this->simple($sql, $page, $title, $field, $data, $field_t, $type, "#*#", '', $format1); Watt_Debug::addInfoToDefault('', 'endUseReadonlyDb'); Watt_Db::endUseReadonlyDb(); return $result; } catch (Exception $e) { Watt_Db::endUseReadonlyDb(); throw $e; } }
/** * 渲染一个指定的 view 文件 * view文件是相对于 view Path 的相对路径+文件名,开始不带 / 或 \ * * * @param Watt_Data_Schema $data * @param String $viewFile 不带扩展名的viewFile * @param Boolean $show * @return String */ public function renderView($data, $viewFile, $show = True) { //$this->_data = $data; $this->addData($data); $this->_viewFile = $this->_getAbsViewPathFilename($viewFile . $this->_viewExt); Watt_Debug::addInfoToDefault(__FILE__ . " " . __LINE__, "use view: " . $this->_viewFile); return $this->render($show); }
private function _loadStrings() { $this->_connectMemcache(); if ($this->_memcache) { if ($this->_memcache->get($this->_memcacheKeyPrefix . $this->_lang . '_LOADED')) { $this->isStringsLoaded = true; Watt_Debug::addInfoToDefault('After load language string from memcache.(cached)'); return true; } Watt_Debug::addInfoToDefault('Before load language string from memcache.'); $langPath = Watt_Config::getLangPath() . $this->_lang . DIRECTORY_SEPARATOR; if (!file_exists($langPath)) { $langPath = Watt_Config::getLangPath() . "default" . DIRECTORY_SEPARATOR; } $this->_loadLangFilesInDir($langPath); //载入备用目录的语言文件 // //$langPath = Watt_Config::getLangPath(1).$this->_lang.DIRECTORY_SEPARATOR; //$this->_loadLangFilesInDir( $langPath ); $this->_memcache->set($this->_memcacheKeyPrefix . $this->_lang . '_LOADED', true); Watt_Debug::addInfoToDefault('After load language string from memcache.'); return true; } else { return false; } }
/** * 结束使用只读数据库 * * @author bobit * Mon Sep 24 16:37:49 CST 200716:37:49 */ public static function endUseReadonlyDb() { self::$_need_use_readonly_db = 0; Watt_Debug::addInfoToDefault('', 'Unset use READONLY DB server'); }
/** * 处理 do * 有可能会返回 goToDo * * 只有一个单词的do,对应的action是 index * * * @param string $do * @return string $goToDo */ protected function processDo($do, $defaultView = "Html") { if ($do == "") { $e = new Watt_Exception(Watt_I18n::trans("ERR_DISPATCH_NODO")); throw $e; } $goToDo = ""; $arrCtrlAndAction = $this->_analyzeDoToControllerAndAction($do); $controller = $arrCtrlAndAction[0]; $action = $arrCtrlAndAction[1]; $doFile = $arrCtrlAndAction[2]; $doAction = $arrCtrlAndAction[3]; //exit( $doFile . "|" . $doAction ); //使用 ob_start 是为了Controller里的 redirect 可以正常使用 if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) { /** * 为了不让服务器过长等待时间,改为不启用Ctrl Buffer * @author terry * @version 0.1.0 * Mon Jan 14 14:41:39 CST 2008 */ ob_start(); } /** * 增加了对页面缓存的支持 */ $cache = null; Watt_Debug::addInfoToDefault('Begin create action [' . $controller . '] [' . $action . ']'); $theCtrl = Watt_Controller_Action::factory($controller, $action); Watt_Debug::addInfoToDefault('After create action'); $viewMenu = isset($_REQUEST["view_menu"]) ? trim($_REQUEST["view_menu"]) == '0' ? false : true : true; $theCtrl->setNeedMenu($viewMenu); $actionCacheTime = $theCtrl->getActionCacheTime($action); if ($actionCacheTime > 0) { $cache = new Watt_Cache($actionCacheTime); if ($cache->cacheCheck()) { //如果符合缓存条件,则会读取缓存文件,并 exit. /** * 改为退出处理,为了记录页面执行时间。 * 这里一定不能 return true. * @author terry * @version 0.1.0 * Mon Jan 14 14:30:43 CST 2008 */ return ''; } } /** * 检查 会话的权限。 * 如果没有权限,抛出一个异常 * 此处别扭 */ $rbac = new Watt_Rbac(); //$rbac->checkSession(Watt_Session::getSession(), $do); $privilege = $rbac->checkActionPrivilege(Watt_Session::getSession(), $theCtrl, $action); if (is_object($privilege) && $privilege instanceof TpmYonghuzhaoquanxian) { if (!$theCtrl->getTitle()) { $theCtrl->setTitle(Watt_I18n::trans($privilege->getQxMingcheng())); } } Watt_Debug::addInfoToDefault('', 'Pre do action..'); if (method_exists($theCtrl, $doAction)) { //执行controller中的action $theCtrl->{$doAction}(); } else { throw new Exception(Watt_I18n::trans("ERR_APP_LOST_ACTION")); } Watt_Debug::addInfoToDefault('', 'After do action..'); $goToDo = $theCtrl->getGoToDo(); $data = $theCtrl->getData(); /** * 改为对 Ctrl 不进行 Buffer 的处理 * @author terry * @version 0.1.0 * Mon Jan 14 15:05:28 CST 2008 */ if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) { if (defined("DEBUG") && DEBUG) { //调试阶段才显示Controller里输出的信息 echo ob_get_clean(); } else { //用户使用阶段不允许 action 里输出显示数据 ob_clean(); } } if ($theCtrl->isNeedView()) { Watt_Debug::addInfoToDefault('', 'Pre load view..'); if ($theCtrl->getViewType()) { $defaultView = $theCtrl->getViewType(); } /** * 创建一个View。将来可以用不同的View代替此View */ //$view = Watt_View::factory( "Html", Watt_Config::getViewPath() ); $view = Watt_View::factory($defaultView, Watt_Config::getViewPath()); $view->setHeader($theCtrl->getHeader()); Watt_Debug::addInfoToDefault('', 'After view factory..'); /** * 读取菜单应该由View来判断 * @author terry * Thu Jul 22 10:46:07 CST 2010 */ if ($theCtrl->isNeedMenu() && strtolower($defaultView) == 'html') { //$theCtrl->isNeedCaidan(); /** * 如果用户已登录,读取菜单信息 * @todo 未登录可能也可以有菜单 */ if ($user_id = Watt_Session::getSession()->getUserId()) { $tpmCaidans = TpmCaidanPeer::getJueseCaidan(Watt_Session::getSession()->getRoleId()); if (count($tpmCaidans)) { $view->setHeader($tpmCaidans, "menu"); } } //读取菜单完 } //$view->renderModel($theCtrl); $view->renderView($data, $this->_getDefaultViewFileOfAction($controller, $action), true); } /** * 与开始的Cache对应 */ if ($actionCacheTime > 0 && $cache instanceof Watt_Cache) { $cache->caching(); } return $goToDo; }