/** * 获得默认的Debuger * * @return Pft_Debug */ public static function getDefaultDebug() { if (!self::$_defaultDebug) { $theDebuger = new Pft_Debug(); if (defined('APP_START_TIME')) { $theDebuger->setStartTime((int) (APP_START_TIME * 1000)); } $theDebuger->begin(); self::$_defaultDebug = $theDebuger; } return self::$_defaultDebug; }
/** * 以Json的方式渲染数据并输出 * * @param boolean $show * @return string */ public function render($show = true) { ob_start(); echo serialize($this->_data); $out = ob_get_clean(); if ($show) { echo $out; } //如果输出debug信息, Json会不正确 Pft_Debug::getDefaultDebug()->clearDebugInfo(); return $out; }
/** * 以PhpArray的方式渲染数据并输出 * * @param boolean $show * @return string */ public function render($show = true) { ob_start(); //这里显示菜单 //这里显示主体部分 //parent::render( true ); reset($this->_data); echo var_export($this->_data); //这里显示底部 $out = ob_get_clean(); if ($show) { //echo "<pre>\n"; echo $out; //echo "\n</pre>"; } Pft_Debug::getDefaultDebug()->clearDebugInfo(); return $out; }
/** * 以XML的方式渲染数据并输出 * * @param boolean $show * @return string */ public function render($show = true) { ob_start(); //这里显示菜单 //这里显示主体部分 //parent::render( true ); reset($this->_data); echo '<?xml version="1.0" encoding="' . $this->_charSet . '"?>' . "\n"; echo Pft_Util_Array::varToXml($this->_data); //这里显示底部 $out = ob_get_clean(); if ($show) { header("Content-type: text/xml; charset=" . $this->_charSet); echo $out; } //如果输出debug信息, XML会报错 Pft_Debug::getDefaultDebug()->clearDebugInfo(); return $out; }
/** * @todo 解决和dialog重复的问题 * * @param boolean $show * @return string */ public function render($show = true) { ob_start(); /** * ajax 也要显示显示 Tq消息 * Tq消息要在 tip 之前 * ajax不显示消息, 此时消息存在 session 里,下次统一发送 */ //echo Tpm_Message_Sender_Tq::getMsgHtml(); /** * 这里显示主体部分 */ parent::render(true); $out = ob_get_clean(); if ($show) { echo $out; } //如果输出debug信息, Ajax会不爽 Pft_Debug::getDefaultDebug()->clearDebugInfo(); return $out; }
/** * 记录: * 使用默认的 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) { if (is_array($msg)) { $msg = var_export($msg, true); } //默认所有日志就记录入 debuger 日志 self::getDefaultLogger()->log($msg, $level, $sourceName, $actorName, $actorId, $exts); if ($level > self::LEVEL_DEBUG) { //self::getDefaultLogger()->log( 'Before DB Log' ); self::getSystemLogger()->log($msg, $level, $sourceName, $actorName, $actorId, $exts); //self::getDefaultLogger()->log( 'After DB Log' ); } /** * 如果是Debug模式,同时输出到屏幕 / 判断debug模式在 addInfoToDefault 中实现 * @author terry * @version 0.1.0 * Mon Sep 24 21:06:25 CST 2007 */ Pft_Debug::addInfoToDefault('Pft_Log::addLog', $msg); return true; }
/** * 以XML的方式渲染数据并输出 * * @param boolean $show * @return string */ public function render($show = true) { // header( "Content-type: application/octetstream" ); // header( "Content-Disposition: attachment; filename=".date('Y-m-d H:i:s').".csv" ); // header('Content-type: application/csv'); // header('Content-Disposition: attachment; filename="xxx.csv"'); ob_start(); //这里显示菜单 //这里显示主体部分 //parent::render( true ); reset($this->_data); /** * 这里显示主体部分 */ parent::render(true); //这里显示底部 $out = ob_get_clean(); if ($show) { echo $out; } //如果输出debug信息, XML会报错 Pft_Debug::getDefaultDebug()->clearDebugInfo(); return $out; }
/** * 处理 do * 有可能会返回 goToDo * * 只有一个单词的do,对应的action是 index * * * @param string $do * @return string $goToDo */ protected function processDo($do, $defaultView = "Html") { if ($do == "") { $e = new Pft_Exception(Pft_I18n::trans("ERR_DISPATCH_NODO")); throw $e; } $goToDo = ""; $arrCtrlAndAction = $this->_analyzeDoToControllerAndAction($do); $controller = $arrCtrlAndAction[0]; $action = $arrCtrlAndAction[1]; $doFile = $arrCtrlAndAction[2]; $doAction = $arrCtrlAndAction[3]; //使用 ob_start 是为了Controller里的 redirect 可以正常使用 //ob_start(); $theCtrl = Pft_Controller_Action::factory($controller, $action); /** * 检查 会话的权限。 * 如果没有权限,抛出一个异常 * 此处别扭 */ $rbac = new Pft_Rbac(); //$rbac->checkSession(Pft_Session::getSession(), $do); $privilege = $rbac->checkActionPrivilege(Pft_Session::getSession(), $theCtrl, $action); if ($privilege instanceof TpmYonghuzhaoquanxian) { if (!$theCtrl->getTitle()) { $theCtrl->setTitle(Pft_I18n::trans($privilege->getQxMingcheng())); } } Pft_Debug::addInfoToDefault('', 'Pre do action.'); if (method_exists($theCtrl, $doAction)) { //执行controller中的action $theCtrl->{$doAction}(); } else { throw new Exception(Pft_I18n::trans("ERR_APP_LOST_ACTION")); } Pft_Debug::addInfoToDefault('', 'After do action..'); $goToDo = $theCtrl->getGoToDo(); $data = $theCtrl->getData(); if (defined("DEBUG") && DEBUG) { //调试阶段才显示Controller里输出的信息 //echo ob_get_clean(); } else { //用户使用阶段不允许 action 里输出显示数据 //ob_clean(); } if ($theCtrl->isNeedView()) { Pft_Debug::addInfoToDefault('', 'Pre load view..'); if ($theCtrl->getViewType()) { $defaultView = $theCtrl->getViewType(); } $view = Pft_View::factory($defaultView, Pft_Config::getViewPath()); $view->setHeader($theCtrl->getHeader()); Pft_Debug::addInfoToDefault('', 'After view factory..'); /** * 如果用户已登录,读取菜单信息 * @todo 未登录可能也可以有菜单 */ if ($user_id = Pft_Session::getSession()->getUserId()) { $tpmCaidans = TpmCaidanPeer::getJueseCaidan(Pft_Session::getSession()->getRoleId()); if (count($tpmCaidans)) { $view->setHeader($tpmCaidans, "menu"); // $menus = array(); // foreach ( $tpmCaidans as $tpmCaidan ) // { // $menus[] = array( $tpmCaidan->getCdMingcheng() // , $tpmCaidan->getCdChuliye() // ); // } // $view->setHeader( $menus, "menu" ); } } //读取菜单完 //$view->renderModel($theCtrl); $view->renderView($data, $this->_getDefaultViewFileOfAction($controller, $action), true); } return $goToDo; }
/** * 结束使用只读数据库 * * @author bobit * Mon Sep 24 16:37:49 CST 200716:37:49 */ public static function endUseReadonlyDb() { self::$_need_use_readonly_db = 0; Pft_Debug::addInfoToDefault('', 'Unset use READONLY DB server'); }
/** * 渲染一个指定的 view 文件 * view文件是相对于 view Path 的相对路径+文件名,开始不带 / 或 \ * * * @param Pft_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); Pft_Debug::addInfoToDefault(__FILE__ . " " . __LINE__, "use view: " . $this->_viewFile); return $this->render($show); }
Pft_Log::addLog('Cache exception : ' . $errorInfo); if (defined('DEBUG') && DEBUG) { echo "<pre>" . $errorInfo . "</pre>"; echo "<pre>" . debug_print_backtrace() . "</pre>"; //todo: 此处转入debug 错误代码处理 switch ($code) { } } else { $_REQUEST['msg'] = $e->getMessage(); $_REQUEST['code'] = $code; include 'error.php'; //header( "Location:?do=error&code=$code&msg=".urlencode($e->getMessage()) ); //header( "Location:?do=error&code=$code&msg=".$e->getMessage() ); } } Pft_Debug::addInfoToDefault('After dispatch.'); if (defined("DEBUG") && DEBUG) { /** * 程序结束 输出调试信息 */ Pft_Debug::getDefaultDebug()->output(); } /** * Record Process Time * @author terry * @version 0.1.0 * Sat Aug 04 13:54:36 CST 2007 */ $endTime = microtime(true); $processTimeLogger = new Pft_Log_File('processTime'); $processTimeLogger->log(($endTime - APP_START_TIME) * 1000, 0, 'ProcessTimeAt MS', "", "", @$_REQUEST['do']);
/** * Enter description here... * * @param string $tplFileName 在本文件所在目录的 tpl 目录下 * @param string $outFileName 要求绝对路径 * @param unknown_type $packageNameForCtrl * @param unknown_type $packageNameForDo * @param unknown_type $tableNameForTable * @param unknown_type $tableNameForVar */ private function _buildPhpFile($tplFileName, $outFileName, $arrNames) { $tpl = file_get_contents(dirname(__FILE__) . "/tpl/" . $tplFileName); /* if( preg_match_all( "/(\\$\\{[\\w_]+\})/", $tpl, $match ) ) { var_dump( $match ); } */ foreach ($arrNames as $key => $varname) { $tpl = str_replace("\${{$key}}", $varname, $tpl); } /** * $arrNames 应包含如下key * * $packageNameForCtrl * $packageNameForDo * $tableNameForTable * $tableNameForVar * $ctrlName * */ //extract( $arrNames ); /* $tpl = str_replace( "\${PackageName}", $packageNameForCtrl, $tpl); $tpl = str_replace( "\${package}", $packageNameForDo, $tpl); $tpl = str_replace( "\${TableName}", $tableNameForTable, $tpl); $tpl = str_replace( "\${var_name}", $tableNameForVar, $tpl); $tpl = str_replace( "\${VAR_NAME}", strtoupper( $tableNameForVar ), $tpl); $tpl = str_replace( "\${ctrlname}", strtolower( $ctrlName ), $tpl); */ //file_put_contents( dirname(__FILE__)."/output/". $outFileName, $tpl ); if (file_exists($outFileName)) { //检验是否已存在输出文件,如果存在,则增加一个时间戳 $outFileName = $outFileName . "." . date("YmdHis", time()); } if (file_put_contents($outFileName, $tpl)) { $info = "Create {$outFileName} success!"; } else { "Create {$outFileName} fail!"; } Pft_Debug::addInfoToDefault(get_class($this), $info); chmod($outFileName, 0777); return $info; }
/** * 功能://添加新功能,用第二个参数来传所有的值 * Tony---Fri Mar 16 20:34:11 CST 2007----20:34:11 */ public function NewDb($sql, $he, $page = false, $type = '', $format1 = false) { Pft_Debug::addInfoToDefault('', 'startUseReadonlyDb'); Pft_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); Pft_Debug::addInfoToDefault('', 'endUseReadonlyDb'); Pft_Db::endUseReadonlyDb(); return $result; } catch (Exception $e) { Pft_Db::endUseReadonlyDb(); throw $e; } }