Пример #1
0
 /**
  * 负责分发错误到日志记录
  */
 public static function errorHandler($errno, $errstr, $errfile, $errline, $obj)
 {
     restore_error_handler();
     restore_exception_handler();
     // 处理@符号的情况
     if (!(error_reporting() !== 0 && $errno)) {
         return;
     }
     switch ($errno) {
         case E_NOTICE:
         case E_USER_NOTICE:
             $errors = "Notice";
             break;
         case E_WARNING:
         case E_USER_WARNING:
             $errors = "Warning";
             break;
         case E_ERROR:
         case E_USER_ERROR:
             $errors = "Fatal Error";
             break;
         default:
             $errors = "Unknown";
             break;
     }
     Flow::Log()->clear();
     Flow::Log()->error(sprintf("%s in %s on line %d", $errstr, $errfile, $errline));
     self::dieErrorLogs();
     return false;
 }
Пример #2
0
 /**
  * 汇报到log里面
  */
 private function _reportLogger()
 {
     foreach ($this->_stat_entries as $stat_name => $stat_entry) {
         $log_row = "[{$stat_name}]";
         if (isset($stat_entry['end_time_ms'])) {
             $stat_entry['cost'] = $stat_entry['end_time_ms'] - $stat_entry['start_time_ms'];
             unset($stat_entry['end_time_ms']);
             unset($stat_entry['start_time_ms']);
         }
         foreach ($stat_entry as $entry_key => $entry_val) {
             $log_row .= "{$entry_key} {$entry_val} ";
         }
         Flow::Log()->debug($log_row);
     }
 }
Пример #3
0
/**
 * 包含数据模型
 * @param $modleName 模型的名字 结尾需要是.class.php
 */
function M($modelName)
{
    global $m;
    isset($m) ? $m : ($m = array());
    if (!array_key_exists($modelName, $m)) {
        $t = (include_once APP_BASE . "/models/" . $modelName . ".class.php");
        if (!$t) {
            throw new FlowException("模型" . $modelName . "载入失败, 没有文件 " . APP_BASE . "/module/" . $modelName . ".class.php");
        } else {
            Flow::Log()->i("模型" . $modelName . "载入成功");
        }
        $m[$modelName] = new $modelName($modelName);
    }
    //$m->setFormName($modleName);
    return $m[$modelName];
}
Пример #4
0
 public function send($from, $to, $subject, $content)
 {
     $from = strip($from);
     if (is_array($to)) {
         $to = implode(";", $to);
     }
     $to = strip($to);
     $headers = 'MIME-Version: 1.0' . "\n";
     $headers .= 'Content-Type: text/html; charset=gbk' . "\n";
     //$headers .= "To: $to \n";
     $headers .= 'From: ' . $from . "\n";
     $subject = "=?gbk?B?" . base64_encode($subject) . "?=";
     $result = mail($to, $subject, $content, $headers);
     if ($result) {
         return true;
     } else {
         Flow::Log()->w($result);
         return false;
     }
 }
Пример #5
0
 protected function _beforeQuery($sql)
 {
     Flow::Log()->debug("[SQL] " . $sql);
     return;
 }
Пример #6
0
 /**
  * 打印页面日志
  *
  */
 public static function showLogs()
 {
     // 打印日志
     $errors = FLow::Log()->getDatas();
     foreach ($errors as $message) {
         error_log("FlowPHP" . implode(" ", $message));
     }
     if (DEV_MODE) {
         if (PHP_SAPI == 'cli') {
             $errors = FLow::Log()->getDatas();
             foreach ($errors as $message) {
                 echo implode(" ", $message);
                 echo "\n";
             }
         } else {
             echo Flow::Log()->getHTML();
         }
     }
 }
Пример #7
0
 /**
  * 执行sql语句
  * @return null | resultset
  * @param sqlstatment $sql
  */
 private function query($sql)
 {
     if (null !== $this->sqlResultSet) {
         return $this->sqlResultSet;
     }
     $querytime_before = array_sum(explode(' ', microtime()));
     $this->lastQuery = $sql;
     $this->sqlResultSet = mysql_query($sql, $this->_identifyId);
     $querytime_after = array_sum(explode(' ', microtime()));
     if (!$this->sqlResultSet) {
         Flow::Log()->e("sql执行失败 :{$sql}  :" . mysql_error($this->_identifyId));
         throw new FlowException("sql_error" . " :{$sql}  :" . mysql_error($this->_identifyId));
     } else {
         Flow::Log()->i("执行语句  :  {$sql} 执行时间 :" . ($querytime_after - $querytime_before));
     }
     return $this->sqlResultSet;
 }
Пример #8
0
 /**
  * 打印输出
  *
  * @param $viewname
  */
 public function display($viewname, $view_data = array())
 {
     $_res = $this->_resource;
     if (!empty($_res)) {
         extract($_res);
     }
     if (!empty($view_data)) {
         extract($view_data);
     }
     $appcache_dir = isset(Flow::$cfg["appcache_dir"]) ? Flow::$cfg["appcache_dir"] : APP_PATH . "/appcache/";
     $cache_dir = $appcache_dir . '/templates/';
     $tpl_dir = APP_PATH . "/templates/";
     // 检测缓存文件夹是否存在
     if (!file_exists($cache_dir)) {
         if (!mkdir($cache_dir, 0777, 1)) {
             throw new Exception("Create Cache Dir " . $cache_dir . " Failed");
         }
     }
     // 模板文件
     $tplfile = $tpl_dir . $viewname . '.php';
     $tpl_path = $tplfile;
     // 缓存文件处理
     $tpl_cachepath = $cache_dir . str_replace("/", "__", $viewname) . "__cache.php";
     // 搜索模板文件是否存在
     if (DEV_MODE && !is_file($tplfile)) {
         throw new Exception("Template File Not Found " . $tplfile);
     }
     // 如果没有在dev_mode且缓存文件最后修改时间比templatefile旧 直接包含缓存
     if (file_exists($tpl_cachepath) && filemtime($tpl_cachepath) > filemtime($tpl_path) && !DEV_MODE) {
         include $tpl_cachepath;
         return;
     }
     Flow::Log()->info("Cache View Expired");
     // 读取模板文件
     $c = file_get_contents($tpl_path);
     // 读取tag
     $tagfilter = new F_View_BaseTags();
     $c = $tagfilter->apply($c);
     // 存储编译后的到文件
     if (strlen($c) > 0) {
         if (file_put_contents($tpl_cachepath, $c)) {
             Flow::Log()->info("Cache File {$tpl_cachepath} Created ");
             include $tpl_cachepath;
         } else {
             throw new Exception("Cache File Create Failed " . $viewname);
         }
     }
 }
Пример #9
0
 /** 将查询到的数据全部删除
  * 注意:会清空所有状态
  * @return $this
  */
 public function delall()
 {
     $where = $this->queryWhere == "" ? "" : " where " . $this->queryWhere;
     $limit = $this->queryLimit == "" ? "" : " limit " . $this->queryLimit;
     try {
         D()->sql("delete from `{$this->tableName}` " . $where . $limit);
     } catch (FlowException $ex) {
         Flow::Log()->e("Module `{$this->tableName}`: 删除数据失败  " . $ex->getMessage());
         throw new FlowException("Module `{$this->tableName}`: 删除数据失败  " . $ex->getMessage());
     }
     $this->resetData();
     return $this;
 }